[R] labels in a boxplot
Andrés Aragón
armandres at gmail.com
Wed Oct 12 15:58:03 CEST 2011
Francesco,
Try cex.axis=0.6
Regards,
Andrés AM
2011/10/12, Francesco Sarracino <f.sarracino at gmail.com>:
> Dear R-listers,
>
> I have a little problem with a boxplot and I hope you can help me figuring
> it out.
> I'll try to make up some data to illustrate the issue. Sorry, if my
> procedures look naive, but these are my first steps in R. Any comments
> and/or suggestions are very welcome.
>
> let's create a vector var1:
> var1 <- rnorm(100)
>
> and 5 five logical vectors. In this case the vectors don't mean anything, I
> just need 5 vectors to illustrate my problem. Each of the 5 vectors
> identifies a geographic area of my interest.
> med <- var1 < -0.7275
> anglo <- var1 > -0.7275 & var1 < -0.09402
> scand <- var1 > -0.09402
> ceast <- var1 < -0.7275 & var1 > -4.10500
> seast <- var1 < 2.5 & var1 > 0.49
>
> and let's put all the vectors together in a data frame:
> data <- data.frame(anglo, med, scand, seast, ceast, var1)
>
> I wish to compare the samples of each region with respect to variable var1.
> Therefore I run:
>
> boxplot(var1[med==1], var1[anglo==1], var1[scand==1], var1[ceast==1],
> var1[seast==1])
>
> Let's make the chart clearer and let's add meaningful labels to the x-axis.
> Hence, I create a new vector containing a label for each of my 5 dummies:
>
> vec <-
> c("Mediterranean","Anglo-Saxon","Scandinavian","Centre-East","South-East")
>
> Now the boxplot is:
> boxplot(var1[med==1], var1[anglo==1], var1[scand==1], var1[ceast==1],
> var1[seast==1], names = vec)
>
> As you can see, some of the labels disappear because of the size of the
> chart (I suppose). I tried to solve the problem by changing the orientation
> of the labels with the las = 3 option (see below):
> boxplot(var1[med==1], var1[anglo==1], var1[scand==1], var1[ceast==1],
> var1[seast==1], names = vec, las = 3)
>
> but the problem is not solved: the names are too long and stand partially
> out of the figure.
> How could I solve this problem? I have been longly google-ing and looking
> into reference manuals, but with no success. In Stata a simple way could be
> just bending each label by 45 degrees, but it seems boxplot does not allow
> such a solution. Furthermore I did not manage to enlarge my figure to place
> everything in.
> Thanks a lot in advance for all your support.
> Best wishes,
> f.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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.
>
More information about the R-help
mailing list