ggplot2 geom_density限制 [英] ggplot2 geom_density limits

查看:655
本文介绍了ggplot2 geom_density限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在调用 geom_density



的调用中删除行一个例子:

  library(ggplot2)
set.seed(1234)

dfGamma =数据帧(nu75 = rgamma(100,0.75),
nu1 = rgamma(100,1),
nu2 = rgamma(100,2))

dfGamma = stack(dfGamma)
ggplot(dfGamma,aes(x = values))+
geom_density(aes(group = ind,color = ind))
pre>

其中产生



我将如何摆脱绘图边缘的垂直蓝线和沿x轴走向的水平线?

解决方案

您可以使用 stat_density()来代替 geom_density )并添加参数 geom =line position =identity

  ggplot(dfGamma,aes(x = v aes(group = ind,color = ind),position =identity,geom =line)


How can I remove the lines at the end of the limits in calls to geom_density?

Here is an example:

library(ggplot2)
set.seed(1234)

dfGamma = data.frame(nu75 = rgamma(100, 0.75),
           nu1 = rgamma(100, 1),
           nu2 = rgamma(100, 2))

dfGamma = stack(dfGamma)
ggplot(dfGamma, aes(x = values)) + 
  geom_density(aes(group = ind, color = ind))

which produces,

How would I get rid of the vertical blue lines at the edges of the plot, and the horizontal one running along the x-axis?

解决方案

You can use stat_density() instead of geom_density() and add arguments geom="line" and position="identity".

ggplot(dfGamma, aes(x = values)) + 
  stat_density(aes(group = ind, color = ind),position="identity",geom="line")

这篇关于ggplot2 geom_density限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆