r - Plot one graph with many variables on x and y axis using ggplot2 -


this data.

localities  variable1  variable2  variable3   variable4 snp              5        1          2            0 bnp              1        2          4            2 mwc              0        3          1            3 

i use reshape2 package combine data. clueless script should use. want put localities in x axis, , variables in y axis. need melt 2 things here? variables need put in different colour well. want put piloint graph.

this have tried, before plotting graph.

cv=c("variables 1", "variables 2", "variables 3", "variables 4"), id=variables) 

if use reshape2 melt data, like

> library(reshape2) > melt(df) using localities id variables    localities  variable value 1         snp variable1     5 2         bnp variable1     1 3         mwc variable1     0 4         snp variable2     1 5         bnp variable2     2 6         mwc variable2     3 7         snp variable3     2 8         bnp variable3     4 9         mwc variable3     1 10        snp variable4     0 11        bnp variable4     2 12        mwc variable4     3 

using these column names, can use ggplot2 plot whatever like, have values in 1 column, can plot them against axis. can use variable column color, if like. simple plot, specifications, using dodging show overlapping points:

library(ggplot2) ggplot(aes(localities, value, colour = variable), data = melt(df)) +      geom_point(position = position_dodge(.1)) 

scatterplot


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -