use*_*000 5 r ggplot2 kernel-density
我正在尝试在ggplot2中的R中创建一个简单的密度图.这是我的代码很好用.
d <- ggplot(result, aes(x=result$baseMeanA))
d + geom_density(colour="darkgreen", size=2, fill="darkgreen") +
scale_x_log10() + scale_y_continuous(limits = c(0, 0.45))
Run Code Online (Sandbox Code Playgroud)
问题是我不能像我想的那样将x轴调整为负数.
scale_x_log10(limits= c(1, 10000))
Run Code Online (Sandbox Code Playgroud)
效果很好,但是
scale_x_log10(limits= c(-1, 10000))
Run Code Online (Sandbox Code Playgroud)
根本不起作用!它给了我这个错误:
if(zero_range(range)){:缺少值需要TRUE/FALSE时出错
请帮忙!
如果限制范围应部分低于零,您可以对变量进行 log10 转换并指定连续比例的限制:
ggplot(result, aes(x=log10(baseMeanA))) +
geom_density(colour="darkgreen", size=2, fill="darkgreen") +
scale_x_continuous(limits = c(-1, 10000) +
scale_y_continuous(limits = c(0, 0.45)) +
Run Code Online (Sandbox Code Playgroud)
你想做的事情没有多大意义,不是吗?负数的对数不是我们可以在 R 中表示的东西
R> log(-1)
[1] NaN
Warning message:
In log(-1) : NaNs produced
Run Code Online (Sandbox Code Playgroud)
那么R应该把轴画到哪里呢?