Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 在geom_bin直方图(ggplot2)中显示下限和上限_R_Ggplot2_Histogram_Plotly_Ggplotly - Fatal编程技术网

R 在geom_bin直方图(ggplot2)中显示下限和上限

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

在下面的柱状图中,如何在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(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)