Resolved: Combo plots part 2- Bar and Line chart in R
in
The Complete Data Visualization Course with Python, R, Tableau, and Excel
/
Bar and Line Chart - Excel - How to Create a Bar and Line Chart
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)
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