Constantly getting unexpected ',' error

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!

So, I was able to fix my comma (,) error, but I have another error, this time is within my ggplot line:

ggplot(HealthNutri, aes(x = EducationSpending14, xend =EducationSpending16, y = CountryName, group = CountryName)) + geom_dumbbell(color = "light blue", colour_x = "darkred", colour_xend = "darkblue", size_x = 0.5, size_xend = 0.5) + scale_x_continuous(label = "Percent", breaks = "Percent", limits = c(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())

Every time I run the ggplot line, it produces the following error:
Error in UseMethod ("rescale") : **
** no applicable method for 'rescale' applied to an object of class "character"

This element has improper syntax I believe...

 + scale_x_continuous(label = "Percent", breaks = "Percent", limits = c(0.0,8.0))

if you remove it you will probably get a chart.
If you want specific help I recommend you make a reprex, we dont have your HealthNutri data to look at

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.