R 在geom_bin直方图(ggplot2)中显示下限和上限
在下面的柱状图中,如何在ggplotly中包含每个箱子的上下限作为工具提示文本R 在geom_bin直方图(ggplot2)中显示下限和上限,r,ggplot2,histogram,plotly,ggplotly,R,Ggplot2,Histogram,Plotly,Ggplotly,在下面的柱状图中,如何在ggplotly中包含每个箱子的上下限作为工具提示文本 library(ggplot2) library(plotly) csub<-data.frame(Anomaly10y = rpois(50,5)) p <- ggplot(csub,aes(x=Anomaly10y)) + stat_bin(binwidth=1, aes(label1 = min(Anomaly10y, na.rm = T), label2 = max(Anomaly1
library(ggplot2)
library(plotly)
csub<-data.frame(Anomaly10y = rpois(50,5))
p <- ggplot(csub,aes(x=Anomaly10y)) +
stat_bin(binwidth=1, aes(label1 = min(Anomaly10y, na.rm = T), label2 =
max(Anomaly10y, na.rm = T)))
ggplotly(p, tooltip = c("label1", "label2"))
库(ggplot2)
图书馆(绘本)
csub也许有更好的解决方案,但您可以使用geom_bar()
来获得您想要的。这里有一个替代方案:
#first extract the data from stat_bin
p <- ggplot(csub,aes(x=Anomaly10y)) + stat_bin(binwidth=1)
temp <- layer_data(p, 1)
#ggplot
pp <- ggplot(data = temp, aes(x =x,y=y, label1 = xmin, label2 = xmax)) +
geom_bar(stat = 'identity', fill = "darkgrey", width = 1)
或
可能有人会使用此选项作为解决方案,但是:
pp <- ggplot(csub,aes(x=Anomaly10y)) +
stat_bin(binwidth=1) +
stat_bin(binwidth=1, geom="text", aes(label=..xmin..), vjust = 2) +
stat_bin(binwidth=1, geom="text", aes(label=..xmax..))
ggplotly(pp)
pp
ggplotly(pp, tooltip = c("label1", "label2"))
pp <- ggplot(csub,aes(x=Anomaly10y)) +
stat_bin(binwidth=1) +
stat_bin(binwidth=1, geom="text", aes(label=..xmin..), vjust = 2) +
stat_bin(binwidth=1, geom="text", aes(label=..xmax..))
ggplotly(pp)