如何在 R 上制作 4 列散点图?

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

我想用四组不同的数据制作散点图。我的组是 MA-H2o、MA-Cu、OA-H2o 和 OA-Cu。 我在这里找到了一个以前的答案,并将每个组放入自己单独的数据集/名称中,效果很好,但他们使用的其余代码对我不起作用。 我还想知道我是否可以在我的轴标题中使用镜面符号,因为我尝试过但它给了我一个错误——意外的符号——所以我不确定。不管怎样,我只想做这个数字,但我不确定怎么做,而且我显然还不太擅长 R ......

我在这里和上半部分使用了其他人的代码,在那里我让小组工作,但现在我有一个错误。这是我用的。

ggplot(df(aes(x = group, y = Olfactory.epithelium.thickness, color = group))) +
  geom_point(size = 4, alpha = 0.7, position = position_jitter(w = 0.1, h = 0)) +
  stat_summary(
    fun.y = mean, geom = "point", shape = 23,
    color = "black", aes(fill = group), size = 4
  ) +
  stat_summary(
    fun.ymin = function(x) (mean(x) - sd(x)),
    fun.ymax = function(x) (mean(x) + sd(x)),
    geom = "errorbar", width = 0.1
  ) +
  theme_bw()

df(aes(x = group, y = Olfactory.epithelium.thickness, color = group)) 错误: 缺少参数“df1”,没有默认值

r ggplot2 scatter-plot dot-plot
1个回答
0
投票

R语言中,有些特殊符号不能出现在名称中,如"+","-","*","/","^","!","$","@"。您可以使用下划线“_”代替“-”。

Cite a case to you, use the built-in database iris.
library(ggplot2)
library(tidyverse)
library(ggpubr)

group=levels(factor(iris$Species))
comp=combn(group,2)
my_comparisons=list()
for(i in 1:ncol(comp)){my_comparisons[[i]]<-comp[,i]}

iris %>%
  ggplot(aes(x=Species,y=Petal.Length))+
  geom_point(aes(color=Species),size = 4, alpha = 0.7, 
             position = position_jitter(w = 0.1, h = 0))+
  stat_summary(
    fun.ymin = function(x) (mean(x) - sd(x)),
    fun.ymax = function(x) (mean(x) + sd(x)),
    geom = "errorbar", width = 0.1
  ) +
  stat_compare_means(comparisons = my_comparisons) +
  theme_bw()
© www.soinside.com 2019 - 2024. All rights reserved.