So, the issue is as follows: I have a dataset which contains
- A
Condition
factor variable with (for this example) 3 levels that need to be plotted on a y axis, - A
Group
factor variable with three levels to be plotted on the x, and - A value for each group at every condition (example data below).
The three levels on the x axis indicate conditions and I would like to display observations at each level on the y in a violin plot format. I am aware of the fact that I need a numeric on the y axis for ggplot to plot these data, but cannot find a solution to solve this issue of nesting specific values (which will change from experiment to experiment) for the y value at each x condition. My progress (after receiving prior help here) has been properly formatting the data into a data frame, and melting the data into a long format for ggplot.
Example data below:
Condition Observation Value
1-----------------A-----------11
1-----------------B-----------7
1-----------------C-----------2
2-----------------A-----------21
2-----------------B-----------2
2-----------------C-----------5
3-----------------A-----------16
3-----------------B-----------45
3-----------------C-----------34
EDIT:
> SampleA <- c(3,7,9)
> SampleB <- c(15,23,33)
> SampleC <- c(21,19,12)
> Observations <- c("Observation 1", "Observation 2", "Observation 3")
> df0 <- data.frame(Observations = as.factor(Observations), SampleA, SampleB, SampleC)
>library(ggplot2)
>df0 <- reshape2::melt((df0, id.vars = "Observations"))