r - How to create a dot plot with a lot of values in ggplot2 -




i created bar chart show population distribution of vietnam. vietnam2015 data:

 year age.group est.pop 1  2015       0-4    7753 2  2015       5-9    7233 3  2015     10-14    6623 4  2015     15-19    6982 5  2015     20-24    8817 6  2015     25-29    8674 7  2015     30-34    7947 8  2015     35-39    7166 9  2015     40-44    6653 10 2015     45-49    6011 11 2015     50-54    5469 12 2015     55-59    4623 13 2015     60-64    3310 14 2015     65-69    1896 15 2015     70-74    1375 16 2015     75-79    1162 17 2015       80+    1878  

this bar chart , wondering if make dot plot instead of bar chart.

library(tidyverse)  vietnam2015 %>%   filter(age.group != "5-9") %>% # somehow weird value creeped data frame, therefor filtered out.   ggplot(aes(x = age.group, y = est.pop)) +   geom_col(colour = "black",            fill = "#ffeb3b") 

enter image description here

now know dot plot data not many data points. can create dot plot 1 dot represents 1000 people or million? communicate better bars consist of people. flowingdata's example , middle image:

histogram explained

maybe can generate values 0 upto est.pop each age.group , plot. i'm sure there other better ways.

library(reshape2)  df2 = dcast(data = df, year~age.group, value.var = "est.pop")  df3 = do.call(rbind, lapply(2:ncol(df2), function(i) data.frame(age.group = names(df2)[i], est.pop = seq(0, df2[,i], 200))))  ggplot(data = df3[df3$age.group != "5-9",],    aes(x = factor(age.group), y = est.pop)) + geom_point() 

enter image description here

data

df = structure(list(year = c(2015l, 2015l, 2015l, 2015l, 2015l, 2015l,  2015l, 2015l, 2015l, 2015l, 2015l, 2015l, 2015l, 2015l, 2015l,  2015l, 2015l), age.group = c("0-4", "5-9", "10-14", "15-19",  "20-24", "25-29", "30-34", "35-39", "40-44", "45-49", "50-54",  "55-59", "60-64", "65-69", "70-74", "75-79", "80+"), est.pop = c(7753l,  7233l, 6623l, 6982l, 8817l, 8674l, 7947l, 7166l, 6653l, 6011l,  5469l, 4623l, 3310l, 1896l, 1375l, 1162l, 1878l)), .names = c("year",  "age.group", "est.pop"), class = "data.frame", row.names = c("1",  "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13",  "14", "15", "16", "17")) 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -