Help adding significant difference bars to plot in R

Hi, I'm a bit of a newbie to R. I have a violin plot comparing measured lengths and widths and would like to put if any of these differences are significant in the plot. Any help with code would be sooo much appreciated.

Thanks

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

Hi
I put my code below as well as a sample of my dataset. Is there anything I can provide?

library(rlang)
library(ggplot2)
library(svglite)
library(Hmisc)
read.csv("Leptothrix_lw.csv", header = TRUE)
data <- read.csv("Leptothrix_lw.csv", header = TRUE)
summary(data)
plot <- plot + geom_violin(aes(color = "Cell_W"))
q <- plot + geom_violin(aes(y =Cell_L , colour = "Cell_L"))
q + labs(y= "Cell Measurements (um)", title= "Cell Length & Width Measurements", colour= "Cell L or W") + stat_summary(
  fun.data="mean_sdl", mult=1, geom="crossbar", width=0.2)

|Name|Cell_L|Cell_W|

|L. cholodnii|2.569|1.082|
|L. cholodnii|3.015|1.029|
|L. cholodnii|2.674|1.137|
|L. cholodnii|2.397|1.123|
|L. cholodnii|2.645|1.197|
|L. mobilis|1.882|0.925|
|L. mobilis|1.931|1.072|
|L. mobilis|1.940|1.049|
|L. mobilis|1.998|0.904|
|L. mobilis|2.366|0.908|

What portion of the guide says to share data in this way? Please advise me so I can correct the guide.

Thanks for replying to my post again to help. my bad on the data format being wrong. Like I said before, I'm a newbie to R, R language, and posting (in proper format) to this R community. Also I don't fully follow your head(iris) example. Is that code? is that how the data looks before going into R? once being in R? If I tried to follow an example I don't understand the data may get messed up in the miscommunication? I just thought I'd copy and paste from my excel so at least the data in the proper categories is there. My advise would be to not expect everyone to follow your guide or know R language enough to follow. Maybe try the example again using the data I provided?

Ok let's talk it through nice and slow.

Iris is a built in dataset in R.
That means you can open r.
Type

iris

and expect to see it.
You should try this and report back.
With it being a special case, something everyone has, there's little need to share it but I show you how to share it.

Run

dput(iris)

This is runnable shareable code that can recreate iris.

Copy the output of the dput into your console and see what happens.

alright, alright! slow definitely works better for me! So I think I did it correctly now but it has all of my data and not just a small sample like I copied and pasted before. Is that ok?

dput(data)
structure(list(Name = c("L. cholodnii", "L. cholodnii", "L. cholodnii",
"L. cholodnii", "L. cholodnii", "L. cholodnii", "L. cholodnii",
"L. cholodnii", "L. cholodnii", "L. cholodnii", "L. cholodnii",
"L. cholodnii", "L. cholodnii", "L. cholodnii", "L. cholodnii",
"L. cholodnii", "L. cholodnii", "L. cholodnii", "L. cholodnii",
"L. cholodnii", "S. natans", "S. natans", "S. natans", "S. natans",
"S. natans", "S. natans", "S. natans", "S. natans", "S. natans",
"S. natans", "S. natans", "S. natans", "S. natans", "S. natans",
"S. natans", "S. natans", "S. natans", "S. natans", "S. natans",
"S. natans", "L. mobilis", "L. mobilis", "L. mobilis", "L. mobilis",
"L. mobilis", "L. mobilis", "L. mobilis", "L. mobilis", "L. mobilis",
"L. mobilis", "L. mobilis", "L. mobilis", "L. mobilis", "L. mobilis",
"L. mobilis", "L. mobilis", "L. mobilis", "L. mobilis", "L. mobilis",
"L. mobilis", "I", "I", "I", "I", "I", "I", "I", "I", "I", "I",
"I", "I", "I", "I", "I", "I", "I", "I", "I", "I", "I", "I", "I",
"I", "I", "I", "I", "I", "I", "I", "I", "I", "I", "I", "I", "I",
"I", "I", "I", "I", "I", "I", "I", "I", "I", "I", "I", "I", "I",
"I", "I", "I", "I", "I", "I", "I", "I", "I", "I", "I", "II",
"II", "II", "II", "II", "II", "II", "II", "II", "II", "II", "II",
"II", "II", "II", "II", "II", "II", "II", "II", "II", "II", "II",
"II", "II", "II", "II", "II", "II", "II", "II", "II", "II", "II",
"II", "II", "II", "II", "II", "II", "II", "II", "II", "II", "II",
"II", "II", "II", "II", "II", "II", "II", "II", "II", "II", "II",
"II", "II", "II", "II", "III", "III", "III", "III", "III", "III",
"III", "III", "III", "III", "III", "III", "III", "III", "III",
"III", "III", "III", "III", "III", "III", "III", "III", "III",
"III", "III", "III", "III", "III", "III", "III", "III", "III",
"III", "III", "III", "III", "III", "III", "III", "III", "III",
"III", "III", "III", "III", "III", "III", "III", "III", "III",
"III", "III", "III", "III", "III", "III", "III", "III", "III",
"III", "III", "III", "III", "III", "III", "III", "III", "III",
"III", "III", "III", "III", "III", "III", "III", "III", "III",
"III", "III", "III", "III", "III", "III", "III", "III", "III",
"III", "III", "III", "III", "III", "III", "III", "III", "III",
"III", "III", "III", "III", "III", "III", "III", "III", "III",
"III", "III", "III", "III", "III", "III", "III", "III", "III",
"III", "III", "III", "III", "III", "III", "III", "III", "III",
"III", "III", "III", "III", "III", "III", "III", "III", "III",
"III", "III", "III", "III", "III", "III", "III", "III"), Cell_L = c(2.569,
3.015, 2.674, 2.397, 2.645, 2.395, 2.472, 2.643, 2.582, 2.428,
2.715, 2.59, 2.596, 2.796, 2.627, 2.467, 2.616, 2.439, 2.361,
2.564, 2.669, 3.117, 2.795, 2.789, 2.947, 2.896, 3.254, 2.933,
2.842, 2.689, 3.299, 2.824, 2.693, 2.986, 2.927, 2.947, 2.694,
3.201, 2.963, 3.188, 1.882, 1.931, 1.94, 1.998, 2.366, 2.01,
2.441, 2.028, 1.995, 2.241, 1.892, 1.831, 1.74, 1.798, 2.166,
2.01, 2.041, 2.028, 1.995, 2.141, 2.481, 2.538, 2.21, 2.207,
2.137, 2.22, 2.433, 2.185, 2.179, 2.279, 2.519, 2.531, 2.326,
2.519, 2.652, 2.222, 2.279, 2.505, 2.346, 2.394, 2.157, 2.45,
2.224, 2.328, 2.515, 2.5, 2.549, 2.418, 2.36, 2.418, 2.442, 2.744,
2.494, 2.418, 2.713, 2.549, 2.543, 2.413, 2.467, 2.67, 2.386,
2.597, 2.271, 2.22, 2.38, 2.676, 2.567, 2.869, 2.732, 2.342,
2.443, 2.361, 2.754, 2.522, 2.334, 2.721, 2.6, 2.597, 2.326,
2.574, 2.961, 3.023, 2.878, 2.127, 2.043, 2.628, 2.764, 2.623,
2.828, 2.636, 2.337, 2.949, 2.796, 2.55, 2.679, 2.411, 2.511,
1.973, 2.965, 2.801, 1.922, 2.444, 2.159, 2.247, 2.534, 2.167,
2.025, 2.404, 2.308, 2.067, 2.483, 2.402, 2.569, 2.464, 2.296,
2.434, 2.54, 2.412, 2.442, 2.393, 2.247, 2.534, 2.167, 2.325,
2.434, 2.628, 2.764, 2.643, 2.827, 2.411, 2.847, 2.574, 2.467,
2.385, 2.534, 2.61, 2.664, 2.643, 2.837, 2.413, 2.386, 2.511,
2.593, 2.501, 2.652, 2.611, 2.865, 2.627, 2.74, 2.517, 2.586,
2.571, 2.693, 2.531, 2.752, 2.681, 2.765, 2.637, 2.44, 2.537,
2.21, 2.308, 2.244, 2.214, 2.326, 2.344, 2.39, 2.29, 2.286, 2.443,
2.21, 2.315, 2.387, 2.315, 2.453, 2.598, 2.522, 2.261, 2.326,
2.517, 2.67, 2.482, 2.543, 2.535, 2.649, 2.611, 2.865, 2.627,
2.74, 2.677, 2.543, 2.842, 2.618, 2.434, 2.808, 2.411, 2.905,
2.512, 2.574, 2.811, 2.27, 2.454, 2.812, 2.354, 2.394, 2.3, 2.916,
2.851, 2.97, 2.34, 2.593, 2.501, 2.652, 2.703, 2.742, 2.916,
2.864, 2.508, 2.522, 2.51, 2.596, 2.505, 2.59, 2.815, 2.613,
2.157, 2.386, 2.511, 2.564, 2.569, 2.921, 2.317, 2.472, 2.442,
2.516, 2.429, 2.5, 2.524, 2.68, 2.851, 1.901, 2.064, 1.925, 1.919,
1.689, 1.986, 2.002, 1.843, 1.9, 1.94, 1.924, 1.927, 1.803, 1.946,
1.656, 1.615, 1.775, 2.001, 1.593, 1.627, 2.759, 2.555, 2.606,
2.323, 2.743, 2.916, 2.676, 2.679, 2.346, 2.865, 2.678, 2.528,
2.895, 2.655, 2.385, 2.549, 2.598, 2.602, 2.923, 2.912), Cell_W = c(1.082,
1.029, 1.137, 1.123, 1.197, 0.989, 1.109, 1.026, 1.055, 1.054,
1.02, 1.079, 1.145, 1.107, 0.995, 0.999, 1.042, 1.142, 1.042,
1.094, 1.111, 1.097, 1, 1.275, 1.222, 1.117, 1.092, 1.081, 1.164,
1.199, 1.117, 1.097, 1.326, 1.163, 1.397, 1.124, 1.252, 1.097,
1.163, 1.072, 0.925, 1.072, 1.049, 0.904, 0.908, 1.198, 0.934,
1.014, 1.113, 1.076, 0.985, 1.002, 1.149, 0.974, 0.978, 1.118,
0.934, 1.014, 1.131, 1.076, 1.072, 1.086, 1.078, 1.088, 1.088,
1.049, 1.211, 1.163, 1.13, 1.023, 1.15, 1.011, 1.166, 1.094,
1.132, 1.111, 1.04, 1.096, 1.006, 1.078, 1.072, 1.124, 1.058,
1.204, 1.172, 1.069, 1.047, 1.145, 1.044, 1.156, 1.211, 1.204,
1.179, 1.152, 1.124, 1.103, 1.102, 1.11, 1.127, 1.169, 1.186,
1.14, 1.241, 1.151, 1.044, 1.111, 1.124, 1.3, 1.299, 1.008, 1.24,
1.29, 1.202, 1.092, 1.092, 1.271, 1.263, 1.207, 1.357, 1.342,
1.103, 0.996, 1.206, 1.163, 1.199, 1.099, 1.236, 1.203, 1.236,
1.163, 1.11, 1.392, 0.961, 1.263, 1.398, 1.235, 1.258, 1.316,
1.377, 1.455, 1.047, 1.066, 1.041, 1.08, 1.091, 1.102, 1.169,
1.179, 1, 1.064, 1.054, 1.165, 1.129, 1.172, 1.059, 1.014, 1.086,
1.086, 1.047, 1.102, 1.091, 1.102, 1.169, 1.179, 1.203, 1.236,
1.163, 1.11, 1.263, 1.198, 1.235, 1.091, 1.102, 1.169, 1.379,
1.213, 1.136, 1.163, 1.131, 1.163, 1.199, 1.029, 0.99, 1.004,
1.017, 1.006, 1.096, 1.125, 1.094, 1.127, 1.059, 1.088, 1.104,
1.037, 1.126, 1.066, 1.145, 1.104, 1.147, 1.136, 1.015, 0.937,
0.987, 0.987, 1.199, 1.029, 0.99, 1.004, 0.919, 0.937, 1.118,
1.029, 0.937, 1.072, 0.995, 0.99, 1.067, 1.111, 0.993, 0.99,
1.04, 1.072, 1.03, 1.017, 1.08, 1.163, 1.078, 1.166, 1.017, 1.006,
1.096, 1.125, 1.14, 1.111, 1.132, 1.024, 1.13, 1.058, 1.032,
1.069, 1.074, 1.04, 1.098, 1.011, 1.088, 1.011, 1.086, 1.03,
1.041, 1.119, 1.058, 1.094, 1.127, 1.059, 1.088, 1.145, 1.077,
1.054, 1.011, 1.086, 1, 1.072, 1.154, 1.086, 1.048, 1.072, 0.975,
1.048, 1.04, 1.106, 0.99, 1.029, 1.035, 1.015, 1.067, 1.111,
0.987, 1.199, 1.004, 1.111, 0.959, 1.186, 0.97, 0.981, 1.023,
1.047, 1.088, 0.908, 0.97, 1.034, 0.933, 1.098, 0.969, 1.081,
1.069, 1, 1.141, 1.011, 1.072, 0.988, 1.072, 1.064, 1.102, 1.13,
1.102, 1.135, 1.163, 1.04, 1.008, 1.145, 1.125, 1.15, 1.183,
1.077, 1.092, 1.13, 1.047, 1.165, 1.032, 1.067)), class = "data.frame", row.names = c(NA,
-320L))

ok wonderful, I have your 'data'.
Now lets scrutinise your code.
after you load your 'data' and show yourself a summary of it ...
theres a statement with plot on both side, not in reference to your data, and not the way a ggplot is typically begun (with ggplot)
Perhaps you redacted too much of your code ?

OH! so maybe I was running it wrong? So, I think I just found it?

plot <- ggplot(data=data, mapping = aes(x=Name, y=Cell_W))
q + labs(y= "Cell Measurements (um)", title= "Cell Length & Width Measurements", colour= "Cell L or W") + stat_summary(
  fun.data="mean_sdl", mult=1, geom="crossbar", width=0.2)

oops bottom part was a note to myself about something else. I think just the top part is what you wanted =)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.