我有这个情节
ggplot(data, aes(D3)) +
geom_histogram(aes(fill=(..count..)/sum(..count..)), stat = "count", na.rm = TRUE, binwidth =1) +
geom_text(aes(y = ((..count..)), label = scales::percent( (..count..)/sum(..count..)) ), stat = "count", vjust = -0.25) +
scale_fill_gradient("", low = "green", high = "red")
如您所见,y轴显示计数而不是百分比。
另一方面,如果我切换到
ggplot(data, aes(D3)) +
geom_histogram(aes(y = (..density..)), binwidth = 1) +
geom_text(aes( label = format(100*..density.., digits=1,), y= ..density.. ), stat= "bin", binwidth =1, vjust = -0.2 ) +
scale_y_continuous(labels = scales::percent)
它输出这个(非常难看)的图,在y轴上为零
如何在第一幅图上调整y轴,即显示百分比而不是计数?或在第二个秒中删除那些零?