[英]Horizontal bar plot using ggplot2 and plotly
給定的圖使用ggplot2生成一個barplot並進行繪圖。 我想使用ggplotly(p)創建一個類似的水平條形圖。 嘗試在geom_bar()中使用屬性coord_flip(),但沒有幫助。 請幫助我,謝謝。
library(plotly)
dat <- data.frame(
time = factor(c("Lunch","Dinner"), levels=c("Lunch","Dinner")),
total_bill = c(14.89, 17.23))
p <- ggplot(data=dat, aes(x=time, y=total_bill)) +
geom_bar(stat="identity")
p <- ggplotly(p)
如果您安裝GGPLOT2的開發版本,你可以改變方向在劇情對象為水平(如描述這里 ):
p <- ggplot(data=dat, aes(x=time, y=total_bill)) +
geom_bar(stat="identity") +
coord_flip()
l = plotly_build(p)
l$data[[1]]$orientation <- "h"
l
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.