【问题标题】:Space specific ares in x axis ggplotx轴ggplot中的空间特定区域
【发布时间】:2018-08-21 10:32:24
【问题描述】:

我有以下脚本:

testFigure <- ggplot(data = final_df, aes(x=final_df$`ng DNA`, 
y=final_df$`count`)) + 
geom_point(col = "darkmagenta") + ggtitle("ng VS Number") + 
xlab(expression(paste("ng"))) + ylab("Num (#)") + 
theme(plot.title = element_text(hjust = 0.5, color="orange", size=18, 
face="bold.italic"),
    axis.title.x = element_text(color="#993333", size=10, face = "bold"),
    axis.title.y = element_text(color="#993333", size=10,face = "bold")) +  
scale_y_log10(breaks=c(0,10,50,200,600))

testFigure+scale_x_continuous(breaks=c(5,50,100,150,200,250,300,350,400)

生成情节:

我想在 X 轴上分隔绘图区域,以便较低的值 0-10,尤其是 0-5,在它们之间更加清晰和间隔,同时保持其他的空间滴答声。

有什么建议吗?

【问题讨论】:

  • 使用scale_x_continuous()trans 参数怎么样?例如:data.frame(x=1:100,y=rnorm(100)) %&gt;% ggplot(aes(x=x,y=y))+geom_point()+scale_x_continuous(trans="log10")

标签: r ggplot2


【解决方案1】:

解决方案 1:

我也注意到你已经做到了,但在错误的轴上

scale_y_log10(breaks=c(0,10,50,200,600))

但似乎你也必须为 x ax 做同样的事情

scale_x_log10(breaks=c(0,10,50,200,600))

解决方案 2:

scale_x_discrete(limits=0:5)

您可以在每个轴上使用比例并对其设置限制

   library(ggplot2)
dt<-data.frame("Name"=sample(c("A","B"),10,replace = T),
               x=sample(1:10,10),y=sample(1:10,10))

ggplot(dt, aes( x= x , y= y))+
  geom_point(stat='identity', aes(shape=Name,colour = Name))+
  scale_x_discrete(limits=1:12)+
  scale_y_discrete(limits=1:12)

【讨论】:

  • @Bella 解决方案对您有帮助吗?
  • 是的,谢谢,确实 scale_x_log10 对 x 轴也有帮助。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-06
  • 1970-01-01
  • 2023-02-03
  • 1970-01-01
  • 2016-12-06
  • 1970-01-01
相关资源
最近更新 更多