R ggplot2-简单图-无法指定对数轴限制 [英] R ggplot2 - Simple plot- cannot specify log axis limits

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

问题描述

我正在尝试在ggplot2中的R中创建一个简单的密度图.这是我的代码,效果很好.

I'm trying to create a simple densityplot in R in ggplot2. Here's my code which works great.

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))

问题是我无法将x轴调整为负数.

The problem is that I cannot adjust the x-axis as I would like, into negative numbers.

scale_x_log10(limits= c(1, 10000))

效果很好,但

scale_x_log10(limits= c(-1, 10000))

根本不起作用!它给了我这个错误:

does not work at all! It gives me this error:

if(zero_range(range)){时出错:缺少需要TRUE/FALSE的值

Error in if (zero_range(range)) { : missing value where TRUE/FALSE needed

请帮助!

推荐答案

如果限制范围应部分低于零,则可以对变量进行log10转换并为连续刻度指定限制:

If the range of the limits should be partly below zero, you could log10-transform your variable and specify the limits for a continuous scale:

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)) +

这篇关于R ggplot2-简单图-无法指定对数轴限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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