Can you turn the labels on a bar graph?

30 views
Skip to first unread message

Chris

unread,
Jul 24, 2015, 11:17:21 PM7/24/15
to Shiny - Web Framework for R
I need to turn the labels on a bar graph, so that I can fit more names into a small space. I wanted to turn the labels 45 degrees, but I don't know if that is possible with the barplot function. Here is the bar graph I have currently and the code I am using.

if(length(PeoplesubCali$Name) < 11){
    barplot(PeoplesubCali$TotalPeople,col = c("Blue","Red","Purple","Green"), xlab="Hospitals", ylab="LWBS%",
            border=NA,ylim=c(0, input$PeopleRange[2]),xpd=FALSE, 
            names.arg = PeoplesubCali$Name)}
      else{
        barplot(PeoplesubCali$TotalPeople,col = c("Blue","Red","Purple","Green"), xlab="Hospitals", ylab="LWBS%",
                border=NA,ylim=c(0, input$PeopleRange[2]),xpd=FALSE 
                )}

Amber James

unread,
Jul 27, 2015, 2:34:01 AM7/27/15
to Shiny - Web Framework for R, cjschm...@gmail.com
This really isn't a shiny question so I am unsure as to why it is in this forum ... But if you switch to ggplot you can use the following code :

    p<-  ggplot(dataToPlot, aes(y = yPlot, x = xPlot, group = group))
    p
<- p+ geom_bar(stat = "identity",  position = position_dodge())
    p
<- p + theme(axis.text.x = element_text(angle = 90, hjust = 1))
    p
<- p + theme(axis.text.y = element_text(angle = 90, hjust = 1))

Best,

Amber

Dario Strbenac

unread,
Jul 27, 2015, 3:00:07 AM7/27/15
to Shiny - Web Framework for R, cjschm...@gmail.com
This is a question which is suitable for the R-help mailing list and not Shiny's mailing list. It has already been asked by another R user and clearly answered.

Chris

unread,
Jul 28, 2015, 3:06:13 PM7/28/15
to Shiny - Web Framework for R, amber....@gmail.com
Thank you! Yeah this is more of an R question, that's my bad. I'll be sure to keep the R questions to other forums next time.
Reply all
Reply to author
Forward
0 new messages