graph - barplot of variables by factors in R -


i wish plot barplots different categories (v, c , s in dummy data) values of different variables (v1-v5) see how ranges of different categories vary across variable. there way in r ?

 factor   v1  v2  v3  v4  v5       v 12.0 8.4 5.3 3.0 3.5       v 11.8 7.5 4.7 2.8 3.7       c 13.2 9.5 5.7 3.0 4.1       c 13.4 9.3 6.3 3.3 3.8       c 10.5 7.7 5.0 2.5 3.2       s 13.1 9.6 5.4 3.1 3.9       s 15.0 9.0 5.1 4.5 9.0 

its should simple code using package, have not been able figure out.

you do:

library(data.table) df2 <- melt(setdt(df), measure.vars = patterns("^v"))  library(ggplot2) ggplot(df2, aes(x=factor, y=value1)) +   stat_summary(aes(fill=variable), fun.y="sum", geom = "bar", position="dodge") +   theme_bw() 

this gives:

enter image description here

used data:

df <- read.table(text="factor   v1  v2  v3  v4  v5 v 12.0 8.4 5.3 3.0 3.5 v 11.8 7.5 4.7 2.8 3.7 c 13.2 9.5 5.7 3.0 4.1 c 13.4 9.3 6.3 3.3 3.8 c 10.5 7.7 5.0 2.5 3.2 s 13.1 9.6 5.4 3.1 3.9 s 15.0 9.0 5.1 4.5 9.0", header=true) 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -