r - ggplot side by side geom_bar() -


After

I want to create a side by side barplot using the geom_bar of this data frame,

  & gt; dfp1 value percent1 1 percent (18,29] 0.20 9 0 9 0 9 1 .45,45,455 2 (29.40] 0.23478261 0.5431034 3 (40.51] 0,154 9 2 9 58 0.3661 9 72 4 (51.62] 0 .1011 9 048 0.17261 9 0 5 (62,95] .0,56,60,377 0.11, 9 4, 9 6 9  

side percents as side by barplots values ​​on the x- axis I have tried to use this code,

  p = ggplot (dfp1, aes (x = value, y = c (percent, percent1)), xlab = "age group ") P = p + geom_bar (stat =" identity ", width = .5)  

However, I get this error : Error: Beauty should be the same length as either a length, or dataProblems: The value is the same period of my percentage and percent1 value, so I am confused Thanks for the help

You will first need to melt your data on value by default. If you have another variable named value , you will need to nominate it (I have called it percent .] Then, fil Set new data by using L to separate data into groups, and by placing bars in one position (instead of above each other) in position = "dodge" P>

  library (reshape2) library (ggplot2) dfp1 & lt; - Melt (dfp1) name (dfp1) [3] & lt; - "percentage" ggplot (dfp1, AES (X = value, Y = percentage, fill = variable), Xlab = "age group") + geom_bar (stat = "identity", width = .5, status = "dodge")  

Enter image details here


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -