0

Using the code below, I could create my ggplotly graph. As shown in the image below, the ggplotly toolbar overlap with the plot's title. How can I move the toolbar to the left side of the plot?

Also, how can I add a space between the title and the graph? I tried to do so by adding "br()" but it did not work?

I was wondering if there any way to remove "County" in the box so it only shows the name of the county (i.e., "Allen County" appears in the box instead of "County: Allen County").

enter image description here

      linedataPlot_60 <- reactive ({


     line_60 <- ggplot(linedata_60(),
           aes(
             x = Year,
             y = Percentage,
            # colour = interaction (County.y, Age_Group),
             colour = County

           )) + geom_line(size = 1)+ #ylim(0,30)+
      geom_point(size = 1.5,
                 shape = 21,
                 fill = "white" ) +   #scale_colour_manual(values=cbbPalette) +
      theme_bw() + #scale_y_continuous(breaks=seq(0,40,1)) +
      theme(legend.title=element_blank(),legend.text = element_text(face = "bold"), plot.title = element_text(
        hjust = 0.5,
        size = 9,
        colour = "Black",
        face = "bold"
      ),axis.text=(blue.bold.10.text), axis.title=blue.bold.10.text)+
      ggtitle(paste(
        input$sex_,
        "Older Population (60 or over) in the Selected Counties",

      "\n",
        "(2010 to 2050)"
      ))
       ggplotly(line_60) 

  })

  output$line_60 <- renderPlotly ({
    linedataPlot_60()
  })
Nader Mehri
  • 514
  • 1
  • 5
  • 21

1 Answers1

1

For tooltip, please modify aes as ggplot(linedata_60(),aes(x = Year,y = Percentage,colour = County,text=paste(County))). Then call ggplotly as ggplotly(line_60,tooltip=c("x","y","text")). To avoid overlapping of title, please update ggtitle as ggtitle(paste("\n",input$sex_,"Older Population (60 or over) in the Selected Counties","\n(2010 to 2050)")).

To move or remove modebar components, please look at this How to download a ggplotly plot with R Shiny downloadHandler?

YBS
  • 19,324
  • 2
  • 9
  • 27