I am trying to use my ggplotly output in shiny, here is my plot.
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.
- Cannot bring the legend down, though i specified the legend position, its not working.
- I cannot create space between axis text & axis labels. See the text "Months" is overlapping with the x-axis months. Similarly in y-axis
- 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
Can someone help me with this please.