Few rows of my data are like:
I am trying to write a loop program in R that takes a set of rows with similar names/values and produces the bar plots in a loop for rows with similar names/values stored in a single column "Variable_name" in R.
so far, I have tried to create a separate data table for each set of rows, filtering by row values and then passing it to ggplot.
[Works but don't want to go through this process] Tedious/Manual process:
data[is.na(data)]<-'NA' #Turning NA as a valid value so that it get's included in the bar diagram.
bar_data1 <- data %>%
filter(Variable_name == 'Gender')
ggplot(bar_data1, aes(x=Levels, y=Count, fill=Levels))+geom_bar(stat="identity")+theme_minimal()+scale_y_continuous(breaks=c(0,10,20,50,100,150))
[Want but doesn't work] I also tried this for loop:
for(i in 1:2){
print(ggplot(data, aes(x=Levels, y=Count, fill=Levels))+geom_bar(stat="identity")+theme_minimal()+scale_y_continuous(breaks=c(0,10,20,50,100,150)))
}
The issue with the loop program that I have written is that it runs forever and ultimately R stops responding. Is it running out of memory? I think there is something wrong with my loop program.
Any advice on how to make it work through the loop program?
