每当我为箱线图编写数据标签时,我的 y 轴一直在变化

问题描述 投票:0回答:1

我正在尝试编写一个箱线图并且轴需要在 -100 和 500 之间,我已经设置了限制并且当我运行它时它工作正常但是每当我运行我的下一段代码来编码数据标签时y轴自动改变:

image with set y axis limits

image after I've coded the data labels

我一直在使用这个代码:

p+scale_x_discrete(name="Time intervals") +
  scale_y_continuous(name="Tumour volume change (%)" , limits = c(-100,500))  
  
p + geom_text(data = tumourvolume, aes(y=Volume+1.85 , label = Volume), 
            position = position_dodge(width=0.5) , size=2)
r ggplot2 boxplot yaxis
1个回答
0
投票

两个代码块都引用相同的基本地块代码 (

p
)。因此,下面的代码块:

p+scale_x_discrete(name="Time intervals") +
  scale_y_continuous(name="Tumour volume change (%)" , limits = c(-100,500))  
  
p + geom_text(data = tumourvolume, aes(y=Volume+1.85 , label = Volume), 
            position = position_dodge(width=0.5) , size=2)

将连续创建两个图:一个应用

scale_
函数,一个添加文本值。如果打算创建一个图以包含
scale_
函数添加文本geom,请使用以下之一:

# CODE OPTION 1: all one block
p + scale_x_discrete(name="Time intervals") +
  scale_y_continuous(name="Tumour volume change (%)" , limits = c(-100,500)) + 
  geom_text(data = tumourvolume, aes(y=Volume+1.85 , label = Volume), 
            position = position_dodge(width=0.5) , size=2)

# CODE OPTION 2: reassign p mid-block
p <- p + scale_x_discrete(name="Time intervals") +
  scale_y_continuous(name="Tumour volume change (%)" , limits = c(-100,500))  
  
p + geom_text(data = tumourvolume, aes(y=Volume+1.85 , label = Volume), 
            position = position_dodge(width=0.5) , size=2)
© www.soinside.com 2019 - 2024. All rights reserved.