Home > Net >  The size of points does not always seem relevant with the size of other points in chart
The size of points does not always seem relevant with the size of other points in chart

Time:03-12

I have the dataframe below:

bt<-structure(list(year2 = c(1955, 1960, 1965, 1970, 1975, 1980, 
1985, 1990, 1995, 2000, 2005, 2010, 2015), issue = c("health", 
"health", "health", "health", "health", "health", "health", "health", 
"health", "health", "health", "health", "health"), country = c("EU", 
"EU", "EU", "EU", "EU", "EU", "EU", "EU", "EU", "EU", "EU", "EU", 
"EU"), pta_count = c(1, 3, 5, 12, 10, 2, 2, 14, 13, 9, 8, 6, 
5), value = c(NA, 2, 4, 11, 7, 1, 2, 13, 12, 9, 8, 6, 5), x = c(1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), x2 = c(1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1), percent = c(NA, 0.666666666666667, 0.8, 
0.916666666666667, 0.7, 0.5, 1, 0.928571428571429, 0.923076923076923, 
1, 1, 1, 1), percvalue = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1)), row.names = c(NA, -13L), class = c("tbl_df", "tbl", "data.frame"
))

and Im trying to create a dot plot in which the grey circle represents always the 100% of value this is why it is always 1 and the green circle inside should represent the percent (value/pta_count). The problem is that the green circles do not seem to be relevant to their value.For example 50% has a very small green circle compared to the grey circle and compared to 66.67% as well. I do not know what the issue is. Maybe I should use another value in the y-axis.

f <- bt   %>%
  ggplot(aes(x = year2))  
  geom_point(aes(y = percvalue, size = percvalue, text = paste0("Year: ", year2)),
             color = "gray")  
  geom_point(aes(y = percvalue, size = percent,
                 # text = paste0("Year: ", year2, "\nPercent: ", round(percent, 3) * 100, "%")), 
                 text = paste0("Year: ", year2, "\nPercentage of all signed PTAs covering NTIs: ", scales::percent(percent))), 
             color = "darkolivegreen")  
  scale_x_continuous(n.breaks = 14)  
  theme_bw() 
  theme(legend.position  =  'none',
        axis.title.y = element_blank(),
        axis.text.y = element_blank())  
  labs(x = "")

CodePudding user response:

You could multiply the proportions by a fixed amount (say 8, though you can use whatever number suits you to make your data clear), and use scale_size_identity. This ensures the size of the dots is always proportional to their value.

ggplot(bt, aes(x = year2, y = percvalue))  
  geom_point(aes(size = 8 * percvalue), color = "gray")  
  geom_point(aes(size = 8 * percent), color = "darkolivegreen")  
  geom_text(aes(y = percvalue, label = scales::percent(percent, 1)),
            nudge_y = 0.25, size = 3)  
  scale_x_continuous(n.breaks = 14)  
  scale_y_continuous(limits = c(0, 2))  
  scale_size_identity()  
  theme_bw()  
  theme(legend.position  =  'none',
        axis.title.y     = element_blank(),
        axis.text.y      = element_blank())  
  labs(x = "")

enter image description here

  • Related