is there any way i could add a vertical line in both the plot at x=15. and also add a plotly to this. i tried but it doesn't seem to work. Thanks
sbucks_new %>%
ggplot(aes(x= category, y= bad_fat, color= category))
geom_boxplot()
coord_flip()
facet_grid(~ milk_dummy)
labs(title= "Unhealthy Fats in Milk drinks by Category",
x= "Drinks Category",
y="Bad Fats (g)")
theme_bw()
CodePudding user response:
Use geom_hline for plotting the vertical line (confusing due to the coord_flip).
Here's an example with mtcars:
p <- ggplot(mtcars, aes(x=factor(carb), y=disp))
geom_boxplot()
facet_wrap(~am2)
geom_hline(aes(yintercept=300))
coord_flip()
Not sure about your other question, but you can quickly convert ggplot object into plotly using ggplotly function.
plotly::ggplotly(p)