I am trying to generate interactive plot (using plotly
) from ggplot2
, and render it to shiny
. The code is like below:
shinyUI(fluidPage(
plotlyOutput("someplot")
))
shinyServer(function(input, output) {
output$someplot <- renderPlotly({
g <- dd %>%
ggplot(aes(x=x, y=y, fill=group)) +
geom_bar(stat="identity", position=position_dodge(0.9))+
geom_text(aes(label=y ), vjust=1.6, size=6,position = position_dodge(0.9))+
theme_minimal()+
#annotate(geom = "text", x = dd$x, y = dd$y - 1.3, label = round(dd$y, 1)) +
theme(axis.text=element_text(size = 15),
axis.title = element_text(size = 30))
ggplotly(g)
})
}
The generated figure looks okay, except for two issues:
- Can not set the font of label and axis (by the
theme
). The output fromggplot
looks good, but the generated plot in shiny does have font. - Can not adjust position of text for barplot in dodge position (
vjust
does not work). I can use theannotate
as in the commented line to adjust position of text of simple bar, but it does not work when the bars are in dodge.