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.
Look at the staxlab function in the plotrix package. On Thu, Sep 6, 2012 at 12:03 PM, David-Arnold <david-arnold at redwoods.edu> wrote:> 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.-- Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com
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.