0

I want to make a scatter/dot plot with four different groups of data. My groups are MA-H2o, MA-Cu, OA-H2o, and OA-Cu. I found a previous answer here and made each group into its own separate data set/name which worked great, but the rest of the code they used did not work for me. I am also wondering if I can use a specula symbol in my axis title because I tried but it gave me an error --unexpected symbol--so I'm not sure. Anyways, I would just like to make this figure but I'm not sure how and I am obviously not very skilled at R yet...

I used someone else's code from here and the first half where I made the groups worked but now I have an error. This is what I used.

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()

Error in df(aes(x = group, y = Olfactory.epithelium.thickness, color = group)) : argument "df1" is missing, with no default

stefan
  • 90,330
  • 6
  • 25
  • 51
  • Please include a [mre] that contains the code you have used and an example of your data, such as the output of `dput(head(mydata))`. – Cloudberry Apr 22 '23 at 06:56
  • 1
    Try with `ggplot(df, aes(....)) +`. You are calling the `df()` function hence the error about the missing `df1` argument. – stefan Apr 22 '23 at 09:09

1 Answers1

0

In R language, some special symbols cannot appear in names, such as"+","-","*","/","^","!","$","@". You can use underscores"_" instead of "-".

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()