I need to make weighted boxplots. I found that ggplot makes them. I would however like to label them with the boxplot statistics (the median, q1 and q3). In the boxplot function in r-base, I could output boxplot statistics and then write a text on the plot to place the labels. How would one do it with ggplot? Vikas
How can I superimpose some text labels on ggplot? I could get weighted quantiles using wtd.quantiles function in Hmisc package. But I can't plot these as labels on the boxplot. My code is as follows. list(c(1:3),c(1:3),c(1:3))->t library(Hmisc) for (i in 1:3) { wtd.quantile(crop.2.list[[i]]$aggincome,weights=crop.2.list[[i]]$Multiplier,probs=c(0.25,0.5,0.75))->t[[i]] } data.frame(y=round(unlist(t)),x=c(1,1,1,2,2,2,3,3,3))->levels library(ggplot) ggplot(crop.2.cast,aesthetics=list(x=Tenurial.status,y=aggincome, weight=Multiplier),labels=c("ts","in"))->p ggtext(ggboxplot(p),aesthetics=list(x=x,y=y,labels=y),data=levels) I am unable to combine ggtext with ggboxplot. Will be grateful if someone could help. Finally, a relatively minor issue at the moment, is it possible to change the x-axis and y-axis labels? Vikas
Hi Vikas, Exactly what do you want to label them with? Generally the purpose of the plot is to avoid having explicit labels - you can just read the numbers of the axes. If you want the exact numbers, presenting them in a table might be more appropriate. I'm not at my development computer at the moment, so I can't give you the exact details, but you will have to calculate the statistics yourself (using the weighted boxplot function in ggplot) and add them to the plot in some way. This should be a bit easier in the next version of ggplot, where the calculation and display are a little more distinct. Hadley On 2/7/07, Vikas Rawal <vikasrawal at gmail.com> wrote:> I need to make weighted boxplots. I found that ggplot makes them. I > would however like to label them with the boxplot statistics (the > median, q1 and q3). In the boxplot function in r-base, I could output > boxplot statistics and then write a text on the plot to place the > labels. How would one do it with ggplot? > > Vikas > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >
Hi, Let me first congratulate you for having written the reshape package. It is very nice and I use it all the time. I wish the documentation was a bit easier. It took me quite some time to find my way through it!! But once I got the hang of how it worked, I just loved it. With ggplot, this is my first encounter!! I actually find the labels on the plots quite useful. For example, to put identifiers for the outlier observations so that my co-researchers can dig deeper into data to see if something is wrong. Similarly, it is useful to be able to put the exact values on the plots. It is much nicer to be able to see the spread of groups of your data while you compare the medians/means!! I will see if I can manage the boxplot.weighted myself. But how does one add the values!! Is the next version round the corner? Is there a way one could do it with the present version? Again, congratulations for all the good stuff you have written!! Vikas