'Decreasing lineheight for y-axis labels on ggplot bar graph for RShiny dashboard
I have tried for hours and I cannot work out to decrease the linehight for the multi-line y-axis titles I have in my ggplot bar graph for an RShiny dashboard, that is convert into a plotly object for use in the dashboard. I want to decrease the spacing between the lines in the axis labels created by the wrapping. I have tried the "lineheight" option within the theme for my ggplot, and have used all different values and cannot get it to work. I have also tried changing different things within the style of the fluidRow/ column/ plotlyOutput within the UI but nothing seems to change. I would appreciate any help, I have added the code below.
within the UI (the graph I am trying to change is in the second fluidRow (tab4)):
mainPanel(
fluidRow(
h2("title"),
column(width = 6, style='width:65vh;height:6vh', plotOutput('tab4b', height="70px"),
column(width = 6))
),
fluidRow(
column(width = 6, style='width:65vh;height:65vh;overflow-y: scroll;', plotlyOutput('tab4')),
column(width = 6, plotlyOutput("Map"))
)
within the server:
geo_op1 <- reactive({
req(input$selgeotab4)
filter(ptsex, AREA_OF_RESIDENCE %in% input$selgeotab4 | NM == 'Engg')
})
plotht1 <- reactive({
if (input$selgeotab4=='Cggg') {
temp <- 3000
}
if (input$selgeotab4=='Caaa') {
temp <-500
}
if (input$selgeotab4=='Looo') {
temp <- 7000
}
if (input$selgeotab4=='Engg') {
temp <- 150
}
else if (input$selgeotab4=='Sttt') {
temp <- 1800
}
return(temp)
})
legendGeo <- reactive({
if (input$selgeotab4=='Cggg') {
temp <- "CG"
}
if (input$selgeotab4=='Caaa') {
temp <- "CA"
}
if (input$selgeotab4=='Looo') {
temp <- "LT"
}
if (input$selgeotab4=='Engg') {
temp <- "Eng"
}
else if (input$selgeotab4=='Sttt') {
temp <- "ST"
}
return(temp)
})
observe({
a <- geographyrates$GEO_NAME[geographyrates$AREA_OF_RESIDENCE == input$selgeotab4]
a <- as.list(sort(unique(a)))
updateSelectInput(session,
inputId='selloctab4',
choices=a
)
})
#bar chart on tab4#
output$tab4<-renderPlotly({
ptsex <- subset(geo_op1(), SEX==input$selsex & PREVDURATION==input$selprev)
ptsex$dummy <- factor(ifelse(ptsex$NM == 'Engg','Engg',
ifelse(ptsex$NM == input$selloctab4, paste("Selected" , legendGeo()), paste("Other" , legendGeo()))),
levels=c('Engg',paste("Other" , legendGeo()), paste("Selected" , legendGeo())))
ptsex$NMnew <- reorder(ptsex$NM, ptsex$Ratep100k)
plot1 <- ggplot(ptsex, aes(x = NMnew, y = Ratep100k, fill=dummy, color=dummy, text=paste(NMnew, Ratep100k)))+
geom_bar(stat='identity', width = 0.6) +
geom_text(size=3, label=paste("", ptsex$Ratep100k), nudge_y = 110) +
coord_flip() +
scale_fill_manual(name='', values = c('#017ABC','grey60','red')) +
scale_color_manual(name='', values = c('#017ABC','grey60','red')) +
ylab('Rate per 100,000') +
xlab('') +
expand_limits(y = max(ptsex$Ratep100k)*1.1)+
theme_bw() +
scale_x_discrete(labels = scales::wrap_format(20))+
theme(panel.border = element_blank(), panel.grid.minor = element_blank(), panel.grid.major = element_blank(),
axis.ticks.y=element_blank(), panel.background = element_rect(fill = 'white'), axis.text.y = element_text(size=8, colour="black"),
axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank(), legend.position="none")
ggplotly(plot1, tooltip="text", height=plotht1(), width=600) #%>%
# style(textposition="right")#
})
I can't work out if this is something to do with sizing of the fluidRow column within the UI or something the ggplotly object created at the end, or something else. Help would be apprieciated!
Thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
