R 如何在ggplot内改变binwidth?
我正在用ggplot做柱状图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)) +
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")