So, here is my code that I am trying to run to create a dumbbell graph for my data of Education Spending (% GDP) by said nations in 2014 and 2016. I keep getting an Unexpected ',' error in my data frame error. Please help!
data = HealthNutri
library(ggplot2)
library(ggalt)
theme_set(theme_classic())
HealthNutri <- HealthNutri[c(131, 190, 230, 110, 89, 74, 186, 61, 62, 94, 184, 172, 59, 52, 249),]
HealthNutri <- data.frame(`CountryName` = c("Iceland", "Norway", "Sweden", "Finland", "Costa Rica", "Burundi", "Niger", "Belgium", "Belize", "Cyprus", "New Zealand", "Moldova", "Barbados", "Aruba (The Netherlands)", "United States")), `EducationSpending(% GDP)14` = c(7.69, 7.68, 7.67, 7.15, 6.87, 6.78, 6.73, 6.64, 6.50, 6.37, 6.35, 6.27, 6.23, 6.16, 4.96)), `EducationSpending(% GDP)16` = c(7.46, 7.98, 7.67, 6.90, 7.10, 4.69, 4.08, 6.55, 7.12, 6.29, 6.44, 5.61, 5.09, 6.19, 3.22))
ggplot(HealthNutri, aes(x= `EducationSpending(% GDP)14`, xend=`EducationSpending(% GDP)16`, y=CountryName, group=CountryName)) + geom_dumbbell(color="#a3c4dc", size=0.75, point.colour.l= "#0e668b") + scale_x_continuous(label="Percent", limits=(0.0,8.0)) + labs(x=NULL, y=NULL, title = "Dumbell chart", subtitle="Percent Change in Education spending: 2014 vs 2018") + theme(plot.title = element_text(hjust=0.5, face="bold"), plot.background=element_rect(fill="#f7f7f7"), panel.background=element_rect(fill="#f7f7f7"), panel.grid.minor=element_blank(), panel.grid.major.y=element_blank(), panel.grid.major.x=element_line(), axis.ticks=element_blank(), legend.position="top", panel.border=element_blank())
plot(data)
I am new to this community, so if the format to ask a question is completely off, please let me know. I can try and fix it. Thank you!