2

I have a data frame with 43 different numeric variables and one categorical variable with 823 rows(patients). I need a violin plot for each numeric variable(each column) grouped based on the categorical variable.The categorical variable has different ethnic groups like "AA","Asian","Native Americans". So I need the 43 violin plots showing the distribution of the each numeric variable(i.e each column) based on the different ethnic groups.The categorical variable would be constant.I am trying to use for loops but I think the code has a problem.It is not working.

The code I am using to generate each violin plot is as follows.
ggplot2.violinplot(data=violin_df, xName='Race',yName='Cluster.1',
                   addDot=TRUE, dotSize=0.8,
                   dotPosition="jitter", jitter=0.2)


Here is the reproducible example dataset and code I am using to 
generate

install.packages("devtools")
library(devtools)
install_github("kassambara/easyGgplot2")
library(easyGgplot2)

data <- matrix(rnorm(150), nrow=15)
data <- as.data.frame(data)
data$groups <- c("group1","group1","group1","group1","group1",
             "group2","group2","group2","group2","group2",
             "group3","group3","group3","group3","group3")
data$groups <- as.factor(data$groups)

ggplot2.violinplot(data=data,xName="groups",yName="V1",
               addDot=TRUE, dotSize=0.8,
               dotPosition="jitter", jitter=0.2)



 ######I need the violin plots for all the 9 column variables in 
 ####the similar manner
 for (i in 1:ncol(data)) {
 png(file = paste("var_", i, ".png", sep=""))
 ggplot2.violinplot(data=data,xName="groups",yName="data[,i]",
                 addDot=TRUE, dotSize=0.8,
                 dotPosition="jitter", jitter=0.2)
 dev.off()
 }
william3031
  • 1,653
  • 1
  • 18
  • 39
  • 2
    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 and desired output that can be used to test and verify possible solutions. Mention all the packages you are using. `ggplot2.violinplot` is not part of `ggplot2`. – MrFlick Sep 25 '19 at 20:05

0 Answers0