Quantcast

dotplots with error bars

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

dotplots with error bars

Colin Wahl
Does anyone have any recommendations for producing dotplots with error
bars? Are there packages available for this? I searched far and wide
and cannot find a suitable option.

I am trying to produce publication-quality figures for my thesis
results. Dotplots (Cleveland dotplots) are a much better form of
summarizing barchart-type data. It does not appear that any of the
main plotting packages in r support dotplots with error bars.
Considering the benefit of these plots, I find it difficult to believe
that they have not been fully integrated into R.

I did find a function "dotplots.errors" available here:
http://agrobiol.sggw.waw.pl/~cbcs/articles/CBCS_5_2_2.pdf.

However, I have found this function absurdly difficult to use when
customizing figures (ordering displays properly, or just simple
getting the function to work.)

I've been struggling for the last few hours to figure out the error:
"error using packet 1 sum not meaningful for factors." Unlike other
packages, this function doesnt have a ?dotplots.errors to help guide
troubleshooting. I presume this is a technicality due to the a numeric
variable being identified as a factor. However, I've double checked
that all the numeric columns in the data frame are not factors, and
the error persists.

I'd really prefer not just calling it quits and resorting to
old-school sloppy bar charts, but if thats what I need to do to finish
this in a timely manner, then so be it.

Thank you,
Colin
M.S. candidate
WWU, Biology dept.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: dotplots with error bars

Jim Lemon
On 02/13/2012 09:51 AM, Colin Wahl wrote:

> Does anyone have any recommendations for producing dotplots with error
> bars? Are there packages available for this? I searched far and wide
> and cannot find a suitable option.
>
> I am trying to produce publication-quality figures for my thesis
> results. Dotplots (Cleveland dotplots) are a much better form of
> summarizing barchart-type data. It does not appear that any of the
> main plotting packages in r support dotplots with error bars.
> Considering the benefit of these plots, I find it difficult to believe
> that they have not been fully integrated into R.
>
> I did find a function "dotplots.errors" available here:
> http://agrobiol.sggw.waw.pl/~cbcs/articles/CBCS_5_2_2.pdf.
>
> However, I have found this function absurdly difficult to use when
> customizing figures (ordering displays properly, or just simple
> getting the function to work.)
>
> I've been struggling for the last few hours to figure out the error:
> "error using packet 1 sum not meaningful for factors." Unlike other
> packages, this function doesnt have a ?dotplots.errors to help guide
> troubleshooting. I presume this is a technicality due to the a numeric
> variable being identified as a factor. However, I've double checked
> that all the numeric columns in the data frame are not factors, and
> the error persists.
>
> I'd really prefer not just calling it quits and resorting to
> old-school sloppy bar charts, but if thats what I need to do to finish
> this in a timely manner, then so be it.
>
Hi Colin,
I am grateful that Marcin Kozak gave plotrix a plug in the paper, and to
show my gratitude, I'll explain how to use centipede.plot to get the
illustration in the paper. Assume that you have the data frame shown on
p70 of the paper:

plant_height<-read.csv("plant_height.csv")

Now, to echo Marcin, let us produce the plot:

library(plotrix)
centipede.plot(t(plant_height[,c(3,2,4)]),
  left.labels=plant_height$group,bg="black",
  right.labels=rep("",13),xlab="Mean plant height (cm) +- SE")

If you want the mean value line:

abline(v=mean(plant_height$est),col="lightgray")

The grid lines are a bit more difficult. You could insert a line into
the function just after the call to box() to draw grid lines under each dot:

abline(h=1:dim(x)[2],col="lightgray",lty=2)

However, this looks like such a good idea that I will add two arguments
to the function to do the vertical line(s) and horizontal grid
automatically, and this option will appear in the next version of plotrix.

Jim

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: dotplots with error bars

Matthieu Dubois-3
In reply to this post by Colin Wahl
Colin Wahl <biowahl <at> gmail.com> writes:

>
> Does anyone have any recommendations for producing dotplots with error
> bars? Are there packages available for this? I searched far and wide
> and cannot find a suitable option.

Dear Colin,

have a look at this page from the R wiki:
http://rwiki.sciviews.org/doku.php?id=tips:graphics-base:errbars

Also, if you want more details on how to do it with ggplot2,
a very nice graphic package, you can have a look here:
http://wiki.stdout.org/rcookbook/Graphs/Plotting%20means%20and%20error%20bars%20(ggplot
2)/

HTH

Matthieu

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: dotplots with error bars

Colin Wahl
In reply to this post by Jim Lemon
Thank you,
Its looking like your package will work for me. I have two questions.

First, how do I rotate the plot 90 degrees so the group labels are on
the x axis and the response value on the y axis?

Second, I'm having trouble with the group labels. I need to order my
groups into meaningful groups to properly display my data. I used the
sort.segs=FALSE argument expecting it to plot the values in the order
of data in the plant_height matrix.

centipede.plot(t(plant_height[,c(3,2,4)]),
        panel.first=c(abline(h=1: 13 , col="lightgray", lty=2),
abline(v=mean(plant_height$est), col="lightgray")),
        sort.segs=FALSE,
        left.labels=plant_height$group, bg="green",
        right.labels=rep("", 13), xlab="Mean plant height (cm) +- SE")

Not only are the groups not plotted in the order as they appear in the
matrix, but the labels are incorrect. The labels cycle through CA-I,
CAIII, CA-II, in that order.

The plot file is attached.

Colin

On Mon, Feb 13, 2012 at 1:31 AM, Jim Lemon <[hidden email]> wrote:

> On 02/13/2012 09:51 AM, Colin Wahl wrote:
>>
>> Does anyone have any recommendations for producing dotplots with error
>> bars? Are there packages available for this? I searched far and wide
>> and cannot find a suitable option.
>>
>> I am trying to produce publication-quality figures for my thesis
>> results. Dotplots (Cleveland dotplots) are a much better form of
>> summarizing barchart-type data. It does not appear that any of the
>> main plotting packages in r support dotplots with error bars.
>> Considering the benefit of these plots, I find it difficult to believe
>> that they have not been fully integrated into R.
>>
>> I did find a function "dotplots.errors" available here:
>> http://agrobiol.sggw.waw.pl/~cbcs/articles/CBCS_5_2_2.pdf.
>>
>> However, I have found this function absurdly difficult to use when
>> customizing figures (ordering displays properly, or just simple
>> getting the function to work.)
>>
>> I've been struggling for the last few hours to figure out the error:
>> "error using packet 1 sum not meaningful for factors." Unlike other
>> packages, this function doesnt have a ?dotplots.errors to help guide
>> troubleshooting. I presume this is a technicality due to the a numeric
>> variable being identified as a factor. However, I've double checked
>> that all the numeric columns in the data frame are not factors, and
>> the error persists.
>>
>> I'd really prefer not just calling it quits and resorting to
>> old-school sloppy bar charts, but if thats what I need to do to finish
>> this in a timely manner, then so be it.
>>
> Hi Colin,
> I am grateful that Marcin Kozak gave plotrix a plug in the paper, and to
> show my gratitude, I'll explain how to use centipede.plot to get the
> illustration in the paper. Assume that you have the data frame shown on p70
> of the paper:
>
> plant_height<-read.csv("plant_height.csv")
>
> Now, to echo Marcin, let us produce the plot:
>
> library(plotrix)
> centipede.plot(t(plant_height[,c(3,2,4)]),
>  left.labels=plant_height$group,bg="black",
>  right.labels=rep("",13),xlab="Mean plant height (cm) +- SE")
>
> If you want the mean value line:
>
> abline(v=mean(plant_height$est),col="lightgray")
>
> The grid lines are a bit more difficult. You could insert a line into the
> function just after the call to box() to draw grid lines under each dot:
>
> abline(h=1:dim(x)[2],col="lightgray",lty=2)
>
> However, this looks like such a good idea that I will add two arguments to
> the function to do the vertical line(s) and horizontal grid automatically,
> and this option will appear in the next version of plotrix.
>
> Jim

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

plantheight.png (37K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: dotplots with error bars

Jim Lemon
On 02/16/2012 05:22 AM, Colin Wahl wrote:

> Thank you,
> Its looking like your package will work for me. I have two questions.
>
> First, how do I rotate the plot 90 degrees so the group labels are on
> the x axis and the response value on the y axis?
>
> Second, I'm having trouble with the group labels. I need to order my
> groups into meaningful groups to properly display my data. I used the
> sort.segs=FALSE argument expecting it to plot the values in the order
> of data in the plant_height matrix.
>
> centipede.plot(t(plant_height[,c(3,2,4)]),
> panel.first=c(abline(h=1: 13 , col="lightgray", lty=2),
> abline(v=mean(plant_height$est), col="lightgray")),
> sort.segs=FALSE,
> left.labels=plant_height$group, bg="green",
> right.labels=rep("", 13), xlab="Mean plant height (cm) +- SE")
>
> Not only are the groups not plotted in the order as they appear in the
> matrix, but the labels are incorrect. The labels cycle through CA-I,
> CAIII, CA-II, in that order.
>
> The plot file is attached.
>
Hi Colin,
First, I'm mildly amazed that centipede.plot will accept embedded
function commands like lattice graphics. Unsorted groups are plotted
starting from the bottom of the plot, so when I call centipede.plot like
this:

centipede.plot(t(plant_height[,c(3,2,4)]),sort.segs=FALSE,
  left.labels=plant_height$group, bg="green",
  hgrid=1:13,vgrid=mean(plant_height$est),
  right.labels=rep("", 13),
  xlab="Mean plant height (cm) +- SE")

I get what I would expect, except for the fact that in modifying the
function, I got the wrong dimension of the "segs" matrix to order the
left.labels, thus the repeating labels. I have fixed that particular bug
and attached the line that fixes the bug for you. I'll wrap up a new
package to fix this for others who may use it.

The big problem is that you want an entirely different plot if you turn
it sideways. What you want in that case is probably:

plot(1:13,plant_height$est,xaxt="n",xlab="Groups",type="n",
  ylab="Mean plant height (cm) +- SE",ylim=c(0,20),
  main="Plant height by group")
abline(v=1:13,col="lightgray",lty=2)
abline(h=mean(plant_height$est),col="lightgray")
points(1:13,plant_height$est,pch=21,bg="green")
dispersion(1:13,plant_height$est,plant_height$upper,plant_height$lower,
  intervals=FALSE)
staxlab(1,at=1:13,labels=plant_height$group)

To fix the label bug, replace this line:

  else seg.order<-1:segdim[1]

with this:

  else seg.order<-1:segdim[2]

Now that's better.

Jim

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Loading...