【问题标题】:Is there a layer using ggplot2 in R to customise the x-axis?在 R 中是否有使用 ggplot2 自定义 x 轴的层?
【发布时间】:2021-07-27 12:46:20
【问题描述】:

我正在尝试创建一个先减小然后增大的 x 轴。这是一个实验室,我们冷却虾并计算每 2C 变化的腹足节拍。

这是一组数据:

Temperature Starved Individual 1
20 57
18 53
16 54
14 50
12 49
10 43
8 41
6 42
4 39
6 41
8 45
10 49
12 57
14 60
16 57
18 58
20 71

这是我使用的代码和它创建的图,但我不知道如何使 x 轴从 20-4-20 开始。

 s1 <- ggplot(wide_artemia_data, aes(temperature, beats_s1)) + 
  xlab("Temperature (C)") + 
  ylab("Number of Pleopod Beats over 30 sec")

s1 + geom_point()

这是我第一次尝试学习编码和使用 R studio,因此非常感谢任何帮助或提示!

【问题讨论】:

    标签: r x-axis


    【解决方案1】:

    您的 x 轴必须是唯一的,但您可以添加一个并显示其他内容:

    
    wide_artemia_data <- read.table(text=
    "Temperature    Starved Individual 1
    20  57
    18  53
    16  54
    14  50
    12  49
    10  43
    8   41
    6   42
    4   39
    6   41
    8   45
    10  49
    12  57
    14  60
    16  57
    18  58
    20  71
    ", header=TRUE, check.names=FALSE, sep="\t" )
    
    wide_artemia_data$id <- 1:nrow( wide_artemia_data )
    s1 <- ggplot(wide_artemia_data, aes(id, `Starved Individual 1`)) +
        scale_x_continuous( labels=wide_artemia_data$Temperature, breaks=wide_artemia_data$id ) +
        xlab("Temperature (C)") +
        ylab("Number of Pleopod Beats over 30 sec")
    s1 + geom_point()
    
    

    结果:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 2015-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-18
      相关资源
      最近更新 更多