0

I'm trying to create a violin plot in ggplot with a dataframe that looks like this

enter image description here

Unfortunately, the violin plot doesn't seem to be calculating the values of each data point under membrane intensity, but rather the quantity of the data points in each group. At least, that's what I assume based on this image due to how similar the violins are.

enter image description here

Here's my code

library(tidyverse)
library(ggplot2)
library("readxl")
read_excel("C:/Users/Jacob/Desktop/School/Gatlin rotation/Data Analysis/2.24.23 ImpB - P150.xlsx")
adjIntDen <- read_excel("C:/Users/Jacob/Desktop/School/Gatlin rotation/Data Analysis/2.24.23 ImpB - P150stuff.xlsx", sheet = "Sheet2")
area <- read_excel("C:/Users/Jacob/Desktop/School/Gatlin rotation/Data Analysis/2.24.23 ImpB - P150stuff.xlsx", sheet = "Sheet3")
adjIntDen <- data.frame(adjIntDen)
colnames(adjIntDen)[1] = "Membrane Intensity"
colnames(adjIntDen)[4] = "Time(m)"
adjIntDen <- drop_na(adjIntDen)
adjIntDen$`Membrane Intensity` <- as.numeric(adjIntDen$`Membrane Intensity`)
adjIntDen <- drop_na(adjIntDen)
intDen <- ggplot(adjIntDen, aes(x="Time(m)", y="Membrane Intensity", fill = Type)) + 
  geom_violin(trim = FALSE)+
  geom_dotplot(binaxis='y', stackdir = 'center', dotsize = 1)
  
              
intDen
Phil
  • 7,287
  • 3
  • 36
  • 66
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. Please [do not post code or data in images](https://meta.stackoverflow.com/q/285551/2372064) – MrFlick Mar 16 '23 at 16:33
  • Best not to change your variable names, and you can't wrap variable names with quotations inside `aes()`. Rather keep your variable names as they are, and add `labs()` as a layer to your ggplot2 code to relabel the axes (i.e. `ggplot(...) + labs(x="Time(m)", y="Membrane Intensity")` – Phil Mar 16 '23 at 16:53
  • Thanks Phil, that helped get me on the right track. The actual problem was with the way I fed the data into R, It's all working now. – Jacob McDaniel Mar 16 '23 at 17:15

0 Answers0