Last answered:

17 Feb 2023

Posted on:

10 Feb 2023

0

Resolved: Combo plots part 2- Bar and Line chart in R

The markers you used in Excel & python for the line chart to specify the points. You didn't talk about it in R. Thanks.

1 answers ( 1 marked as helpful)
Instructor
Posted on:

17 Feb 2023

0

Hi Roman, 

thanks for reaching out! You can include points on the line chart with ggplot. It's rather a hack that adds points on the chart, but I think it looks quite alright. 

Here is an example code which add the points to the line chart:

combo <- ggplot(df_kdnuggets, 
                aes(x = Year, 
                y = Participants, Python.Users)) +
         geom_bar(aes(y = df_kdnuggets$Participants), 
                  stat = "identity",
                  fill = "black") +
         geom_line(aes(y = df_kdnuggets$Python.Users*max(df_kdnuggets$Participants)),
                   stat = "identity", 
                   color = "red", 
                   size = 2) +      geom_point(aes(y=df_kdnuggets$Python.Users*max(df_kdnuggets$Participants)),
             stat = "identity", 
             color = "red", 
             size = 5) +
        scale_y_continuous(sec.axis = sec_axis(~./max(df_kdnuggets$Participants)*100, 
              name = "Python Users in %")) +
        ggtitle("KD Nuggets Survey Python Users (2012 - 2019)") 

Hope this helps!


Best, 

365 Eli

Submit an answer