ggplot() +geom_density(aes(density.1), stat = "density") 密度图对应的统计变换函数是stat_density(): p1 <- ggplot() + stat_density(aes(density.1), geom = "area") p2 <- ggplot() + stat_density(aes(density.1), geom = "line") p1 + p2 如果把geom_density()函数中的统计变换参数从...
theme_bw() # 黑白主题 p 组距自动设置为全距÷30,不满意可手动设置,多试几次。 组距过宽:丧失数据的内在结构 组距过窄:无法体现整体特性 binwidth = 0.5 1.2核密度估计曲线 可将直方图与密度曲线重叠显示: p = ggplot(iris, aes(x = Sepal.Length)) + geom_histogram( aes(y = after_stat(density)),...
alpha = 0.3) + stat_function(fun = dnorm, args = list(mean = 0, sd = 1)) + geom_histogram(data = dat[dat$met == 'Metric12', ], breaks = seq(-10, 10, 0.5), mapping = aes(y = -after_stat(density)), colour = "black", alpha = 0.3)+ coord_cartesian(xlim = c(-10, ...
= after_stat(density * n/nrow(df))。由于您正在管道传输数据框,因此需要执行after_stat(density *...
但是新版本可以用after_stat()来实现: ggplot(mpg, aes(x =displ)) + geom_histogram(aes(y = after_stat(density))) 也可以直接调整颜色(加了透明度): ggplot(mpg,aes(class,hwy))+geom_boxplot(aes(colour=class,fill=after_scale(alpha(colour,0.4))) image...
但是新版本可以用after_stat()来实现: 代码语言:javascript 复制 ggplot(mpg,aes(x=displ))+geom_histogram(aes(y=after_stat(density))) 也可以直接调整颜色(加了透明度): 代码语言:javascript 复制 ggplot(mpg,aes(class,hwy))+geom_boxplot(aes(colour=class,fill=after_scale(alpha(colour,0.4))) image...
ggplot(diamonds,aes(carat,after_stat(count),fill=cut))+geom_density(position="fill") 类似于直方图,我们也可以绘制镜像密度图 data<-data.frame(var1=rnorm(1000),var2=rnorm(1000,mean=2))ggplot(data,aes(x=x))+# Topgeom_density(aes(x=var1,y=after_stat(density)),fill="#69b3a2")+geom...
做了这么多数据地图,是时候该总结一些心得和理念了,今天这篇讨论ggplot2所支持的数据地图素材格式。
cars + stat_bin2d(aes(fill = after_stat(density)), binwidth = c(3,1))cars + stat_density(aes(fill = after_stat(density)), geom = "raster", position = "identity")cars + stat_density(aes(fill = after_stat(count)), geom = "raster", position = "identity")...
ggplot(home_data, aes(x = price, y = after_stat(density))) + geom_histogram() + geom_vline(aes(xintercept = mean_price), price_stats, color = "red", linewidth = 2) + geom_density(color = "green", linewidth = 2) Powered By Notice that the numbers on the y-axis have change...