【问题标题】:Problems with the size of the labels of the plots in RR中地块标签大小的问题
【发布时间】:2021-08-21 13:34:50
【问题描述】:

我对地块标签的大小有疑问。所以,这是代码:

column1 <- c(0.18936045, 0.55010315,  0.23474801, 0.02578839)
column2 <- c(0.20522653, 0.51235168, 0.26060781, 0.02181398 )

example_data <- 
  data.frame(
    rowNames = c('[-2.34898,-0.83219]', '(-0.83219,0.684599]', '(0.684599,2.20139]', '(2.20139,3.71818]'),
    column1 = column1,
    column2 = column2
  )

plot(data = example_data, column1 ~ column2, xlab = "Marginal probs scaledsci",
     ylab = "Actual probs from data", pch = 20, col = 'blue')
text(data = example_data, column1 ~ column2, labels = rowNames, cex = .6, pos = 2.99, col = 'red')

这是我得到的情节: plot obtained

所以,我希望所有带有标签的点都可见。那么,有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: r plot axis-labels


    【解决方案1】:

    对于情节我更喜欢ggplot。当我遇到标签位置问题(与数据点重叠等)时,我经常添加包ggrepel 的功能。下面的例子。

    library(ggplot2)
    library(ggrepel)
    ggplot(example_data, aes(x = column1, y = column2)) + geom_point(size = 4, col = "blue") + labs(x = "Marginal probs scaledsci", y = "Actual probs from data") + geom_text_repel(label = example_data$rowNames, col = "red", nudge_y = 0.02) +
    theme_bw() +  theme(text = element_text(size = 15))
    

    nudge_y 参数以 0.02 个单位的 y 变量移动标签。它是可选的,但在我看来更好看。

    【讨论】:

      【解决方案2】:

      如果你想保持你的文本位置相对于你用pos参数定义它的方式,一种选择是增加x轴范围的限制(特别是在左侧),例如:

      xlim2 <- {r2=diff(range(column1))*.6; c(mean(column1)-r2, max(column1))}
      
      plot(data = example_data, column1 ~ column2, xlab = "Marginal probs scaledsci",
           ylab = "Actual probs from data", pch = 20, col = 'blue', xlim=xlim2)
      text(data = example_data, column1 ~ column2, labels = rowNames, cex = .6, pos = 2.99, col = 'red')
      

      【讨论】:

        猜你喜欢
        • 2020-07-10
        • 1970-01-01
        • 2019-05-13
        • 2013-11-17
        • 1970-01-01
        • 1970-01-01
        • 2011-03-25
        • 1970-01-01
        • 2021-10-29
        相关资源
        最近更新 更多