0

I am trying to use my ggplotly output in shiny, here is my plot.

enter image description here

Here is my script,

    output$Plot1 <- renderPlotly({
  resourcenoplot <- 
    resultsdf2 %>% 
    filter(region == input$region2) %>%
    ggplot()+
    geom_bar(aes(x=mon, y= round(totalresources,2), fill=ValuerType,
                 text = paste(ValuerType,": ", round(totalresources,2))),
             position="stack",stat = "identity") +
    xlab("\nMonths")+
    ylab("Number of Resources\n\n") +
    guides(fill=guide_legend(title=NULL,reverse=T))+
theme(axis.text.x=element_text(angle=50),
legend.position="bottom",legend.background = element_rect(fill="white",size=0.5, linetype="solid",colour ="darkblue"))

  q <- ggplotly(resourcenoplot,tooltip = c("text"))
  q
})

Here is where i am using this plot in server.R in shiny,

tabPanel("Typewise Utilisation",br(),fluidRow(wellPanel(htmlOutput("selectRegion2")),
                                                        plotlyOutput("Plot1",width = "100%", height = "450px")))

I dont know what's wrong with this code, I have two issues with this.

  1. Cannot bring the legend down, though i specified the legend position, its not working.
  2. I cannot create space between axis text & axis labels. See the text "Months" is overlapping with the x-axis months. Similarly in y-axis
  3. If I specify x-axis text angle to be 90 degree, its showing full Month name, here I have specified 70 degree, see the starting part of my month names is cut off.

If I increase the plot size in plotlyOutput("Plot1",width = "100%", height = "450px") , its just increasing the plot size and the issues remain the same.

EDIT 1 :- Subset of the data. This is how the whole dataset looks like enter image description here

Can someone help me with this please.

ds_user
  • 2,139
  • 4
  • 36
  • 71
  • Could you provide a reproducible data sample? – prateek1592 Sep 27 '16 at 05:10
  • Yes. Updated the screenshot of how the data look like. – ds_user Sep 27 '16 at 05:20
  • 3
    Please provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). We cannot type up your dataset from a screenshot to run your code. The data doesn't have to be your actual data; it just has to have the same problem as your actual problem so we can help fix it. – mathematical.coffee Sep 27 '16 at 05:41
  • 2
    Also, do you know if the problem is with ggplot or with plotly? If you make this plot with ggplot and not with plotly, does the graph display OK? If so, then at least we know the problem is more likely to be with plotly and/or shiny. – mathematical.coffee Sep 27 '16 at 05:42

0 Answers0