以此为例:Plot every column in a data frame as a histogram on one page using ggplot
假设我想生成多个直方图,就像那个例子一样。是否可以这样做,但对于一个变量,具有不同的尺度?不同的尺度将是当天的不同划分,如24h / 12h / 6h / 4h
答案 0 :(得分:0)
扩展@Prasanna Kumar的答案并回复@Hugo Torres,您可以使用“ ggpubr”包来组合多个直方图
library(ggpubr)
attach(mtcars)
p1<-ggplot(mtcars, aes(x=mpg)) + geom_histogram(binwidth=30,color="darkblue", fill="lightblue") + ggtitle("Histogram of mpg (binwidth=30)")
p2<-ggplot(mtcars, aes(x=mpg)) + geom_histogram(binwidth=10,color="darkblue", fill="lightblue") + ggtitle("Histogram of mpg (binwidth=10)")
p3<-ggplot(mtcars, aes(x=mpg)) + geom_histogram(binwidth=7,color="darkblue", fill="lightblue") + ggtitle("Histogram of mpg (binwidth=7)")
p4<-ggplot(mtcars, aes(x=mpg)) + geom_histogram(binwidth=5,color="darkblue", fill="lightblue") + ggtitle("Histogram of mpg (binwidth=5)")
ggarrange(p1,p2,p3,p4)
结果如下: