嗨,我有以下东西

ggplot(df, aes(x= nlk_percent ,y= c_percent, color=nlk)) +
  geom_point(position = position_jitter(width = 0.05, height = 0), size=7, alpha=.3) + 
  geom_smooth(method=lm
              , se=FALSE
              , fullrange=TRUE
  )+
  theme_classic() +  
  stat_cor(
    method = "pearson", label.x.npc = .65, label.y.npc = 0 
  )

this produces the following plot, enter image description here

然而,即使我将labe.y.npc设置为0或"Bottom",标签也会保持在中间.有没有什么办法来解决这个问题?我想把这个放在情节的右下角.

提前谢谢你.

这是数据框.

df=structure(list(nlk = c("nlk_active", "nlk_rest", "nlk_active", 
"nlk_rest", "nlk_rest", "nlk_active", "nlk_rest", "nlk_active", 
"nlk_active", "nlk_rest", "nlk_active", "nlk_rest", "nlk_rest", 
"nlk_active", "nlk_rest", "nlk_active", "nlk_active", "nlk_rest", 
"nlk_active", "nlk_rest", "nlk_rest", "nlk_active"), nlk_percent = c(3.18269229751619, 
4.82171021503467, 2.29865831556452, 3.65306001710456, 5.61618123133188, 
3.35895882583233, 5.23610988988963, 3.10768786931437, 4.72410451986685, 
5.55642941544957, 2.88752527074159, 4.08406426478847, 5.69209237542757, 
3.64270157183323, 5.73335434061383, 3.99367436175058, 2.52857131887076, 
6.01100356443267, 3.79493566280354, 4.67016051412663, 4.73822740036724, 
3.96993327469786), c_percent = c(4.18507363787676, 4.18507363787676, 
1.13750352374994, 1.13750352374994, 3.35049724708413, 3.35049724708413, 
3.12928301694497, 3.12928301694497, 2.59215800212536, 2.59215800212536, 
0.263034405833794, 0.263034405833794, 5.05093696522523, 5.05093696522523, 
4.41751500288509, 4.41751500288509, 4.60880924267552, 4.60880924267552, 
0.748461233004036, 0.748461233004036, 0.124328135002202, 0.124328135002202
)), row.names = c(1L, 3L, 6L, 8L, 10L, 12L, 14L, 16L, 18L, 20L, 
21L, 23L, 25L, 27L, 29L, 31L, 34L, 36L, 37L, 39L, 42L, 44L), class = "data.frame")

推荐答案

如果你阅读它的描述,它被归一化在父坐标的0和1之间,所以,它真正做的是 Select 一个点,自然范围的某个百分比.因为没有负的Y值,所以不能使用该值将标签放置在Zero下方.

因为根本没有真正的理由显示负值,所以最容易做的事情是将曲线图的y限制设置为-.15,然后它会看起来更好.

ggplot(df, aes(x= nlk_percent ,y= c_percent, color=nlk)) +
geom_point(position = position_jitter(width = 0.05, height = 0), size=7, alpha=.3) + 
geom_smooth(method=lm
            , se=FALSE
            , fullrange=TRUE
)+
ylim(-.15, 6)+
theme_classic() +  
stat_cor(
    method = "pearson", label.x.npc  =.68 , label.y.npc =.025
)

enter image description here

R相关问答推荐

基于shiny 应用程序中的日期范围子集xts索引

带有gplot 2的十字舱口

从嵌套列表中智能提取线性模型系数

如何根据R中其他列的值有条件地从列中提取数据?

在RStudio中堆叠条形图和折线图

如何在R forestplot中为多条垂直线分配唯一的 colored颜色 ?

SHINY:使用JS函数应用的CSS样式显示HTML表格

使用`Watch()`和`renderUI()`时,不再满足仍出现在SHILINY AFTER条件中的条件输入

在GG图中绘制射线的自动程序

将选定的索引范围与阈值进行比较

汇总数据帧中的复制列,保持行的唯一性

在R中创建连续的期间

我们如何在R中透视数据并在之后添加计算

自动STAT_SUMMARY统计与手动标准误差之间的差异

为什么在写入CSV文件时Purrr::Pwalk不起作用

有没有办法将不等长的列表转换为R中的数据帧

R预测包如何处理ARIMA(Auto.arima函数)中的缺失值

为什么将负值向量提升到分数次方会得到NaN

生存时间序列的逻辑检验

如何在R中创建这些列?