Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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 如何在ggplot内改变binwidth?_R_Ggplot2_Histogram - Fatal编程技术网

R 如何在ggplot内改变binwidth?

R 如何在ggplot内改变binwidth?,r,ggplot2,histogram,R,Ggplot2,Histogram,我正在用ggplot做柱状图 p <- ggplot(TotCalc, aes(x=x,y=100*(..count../sum(..count..)))) + xlab(xlabel) + ylab(ylabel) + geom_histogram(colour = "darkblue", fill = "white", binwidth=500) 我该怎么做呢?休息一下怎么样 x <- rnorm(100) ggplot(NULL, aes(x)) +

我正在用ggplot做柱状图

p <- ggplot(TotCalc, aes(x=x,y=100*(..count../sum(..count..)))) + 
    xlab(xlabel) + ylab(ylabel) +
    geom_histogram(colour = "darkblue", fill = "white", binwidth=500)

我该怎么做呢?

休息一下怎么样

x <- rnorm(100)
ggplot(NULL, aes(x)) + 
  geom_histogram(breaks = c(-5, -2, 0, 5), 
  position = "identity", colour = "black", fill = "white")

x使用
breaks
position=“dodge”

例如:

没有您的数据,但对于您的示例:

p <- ggplot(TotCalc, aes(x=x,y=100*(..count../sum(..count..)))) +
     xlab(xlabel) + ylab(ylabel) +
    geom_histogram(colour = "darkblue", fill = "white", breaks=cumsum(c(180,100,110,160,200,250,1000,3000)), position="dodge")
p
ggplot(mtcars,aes(x=hp))+geom_histogram(breaks=c(50,100,200,350),position="dodge")
p <- ggplot(TotCalc, aes(x=x,y=100*(..count../sum(..count..)))) +
     xlab(xlabel) + ylab(ylabel) +
    geom_histogram(colour = "darkblue", fill = "white", breaks=cumsum(c(180,100,110,160,200,250,1000,3000)), position="dodge")