geom_density(aes(density.1), stat = "bin", bins = 20, col = "black") 直方图和折线图的纵轴都是「计数」,而密度图的纵轴是「比例」,那能不能把折线图或直方图的纵轴也换成比例呢? 可以的。因为统计变换bin生成的结果是count,它以隐形变量的形式被当作y参数。使用after_stat()函数可以将统计变换的结...
ggplot(diamonds, aes(carat, fill = cut)) + geom_density(position = "stack") 绘制堆积密度图,可能通常并不是想要看密度的堆积形式,而可能更想要看的是数量的堆积形式 ggplot(diamonds, aes(carat, after_stat(count), fill = cut)) + geom_density(position = "stack") 百分比密度图 ggplot(diamonds, ...
mapping = aes(y = after_stat(density)), colour = "black", 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...
Cloud Studio代码运行 ggplot(mpg,aes(x=displ,y=..density..))+geom_histogram() image 但是新版本可以用after_stat()来实现: 代码语言:javascript 代码运行次数:0 复制 Cloud Studio代码运行 ggplot(mpg,aes(x=displ))+geom_histogram(aes(y=after_stat(density))) 也可以直接调整颜色(加了透明度): 代码语...
EN做了这么多数据地图,是时候该总结一些心得和理念了,今天这篇讨论ggplot2所支持的数据地图素材格式。
# Load statip into the current R sesssion # Plot a histogram # Plot a box plot library(patchwork) # Get the variable to examine # Create a function that returns a density plot 无计算 计算 未连接 查看 内核未连接 需要帮助? 请参阅我们的疑难解答指南或通过报告问题提供具体反馈。
# Load statip into the current R sesssion # Plot a histogram # Plot a box plot library(patchwork) # Get the variable to examine # Create a function that returns a density plot 无计算 计算 未连接 查看 内核未连接 需要帮助? 请参阅我们的疑难解答指南或通过报告问题提供具体反馈。
这是我试过的。我不太确定y=stat(密度)是否符合我的要求: ggplot(d, aes(x = Depression, fill = Cohort)) + geom_histogram(aes(y = stat(density)), position = "dodge", binwidth = 0.5) + theme_minimal() 以下是一些数据: structure(list(Cohort = c("Fall", "Spring", "Summer", "Fall"...
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) Notice that the numbers on the y-axis have changed. ...
tidy_movies %>% distinct(title, year, length, .keep_all=TRUE) %>% ggplot(aes(x=Genres)) + geom_bar() + geom_text(stat='count', aes(label=after_stat(count)), vjust=-1) + scale_x_upset(n_intersections = 20) + scale_y_continuous(breaks = NULL, lim = c(0, 1350), name =...