[R] No room for labels in barplot

Rui Barradas ruipbarradas at sapo.pt
Thu Sep 6 20:59:31 CEST 2012


Hello,

1. With R-2.15.1 on Windows 7 your first plot places all labels when you 
maximize the graphics device.

2. To place the labels in your second plot you can change the margin 
settings:

op <- par(mar = c(7, 4, 4, 2) + 0.1)  # default is c(5, 4, 4, 2) + 0.1
barplot(sales,ylim=c(0,2500),las=2)
par(op)

See ?par

Hope this helps,

Rui Barradas

Em 06-09-2012 19:03, David-Arnold escreveu:
> All,
>
> I have:
>
> sales <- c(2300,900,155,102,42,10)
> names(sales) <- c("Christmas","Valentine's Day",
>             "Mother's Day","Father's Day",
>             "Thanksgiving","New Year's Day")
> barplot(sales,ylim=c(0,2500))
>
> But it doesn't place all of the name labels on the plot. So I tried:
>
> sales <- c(2300,900,155,102,42,10)
> names(sales) <- c("Christmas","Valentine's Day",
>             "Mother's Day","Father's Day",
>             "Thanksgiving","New Year's Day")
> barplot(sales,ylim=c(0,2500),las=2)
>
> But there wasn't enough room at the bottom margin for the labels. Then I tried:
>
> sales <- c(2300,900,155,102,42,10)
> names(sales) <- c("Christmas","Valentine's Day",
>             "Mother's Day","Father's Day",
>             "Thanksgiving","New Year's Day")
> barplot(sales,horiz=TRUE,xlim=c(0,2500),las=1)
>
> Still, not enough room in the margin for the labels. Now, I am going to be introducing students to barplots in R tonight and I'm looking for a simple way to fix this label problem without scaring them too much.
>
> Any thoughts?
>
> D.
> ______________________________________________
> 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