r - How to plot Row.names on x axis with x and y columns on y axis? -


i have 3 columns, row.names, x, , y.

how plot row.names on x axis x , y on y axis, compare lines of x vs y?

    row.names                      x           y 1   bare_nuclei                   na          na 2   bland_chromatin         5.979253    2.100437 3   clump_thickness         7.195021    2.956332 4   marginal_adhesion       5.547718    1.364629 5   mitoses                 2.589212    1.063319 6   normal_nucleoli         5.863071    1.290393 7   single_eipthelial       5.298755    2.120087 8   uniformity_cell_shape   6.560166    1.443231 9   uniformity_cell_size    6.572614    1.325328 

let's use ggplot2:

r/ggplot2 needs have data in "long" format (meaning 1 observation per row) create many types of graphs.

we use melt make transformation, using row.names id.vars: melt(data,id.vars="row.names"). assign row names x axis, , column generated melt, called value y values. finally, use geom_bar color x , y values, , split them separate bars, using position="dodge".

require(ggplot2) require(reshape2)  df1 <- melt(data,"row.names")  g1 <- ggplot(df1, aes(x = row.names, y=value)) +   geom_bar(aes(fill=variable),stat="identity", position ="dodge") +    theme_bw()+    theme(axis.text.x = element_text(angle=-40, hjust=.1)) 

enter image description here


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -