-2

I have uploaded an excel document into R (data=myData) with 32 countries and their happiness index on the World Happiness Report (numerical variable name 'HAPPINESS'). I have also included data on things like their public spending on healthcare (PSH), public spending on education (PSE) as well as a categorical variable that represents each countries ideology (IDE). Basically what I'm trying to do is create a bubble chart using ggplot or some other function to show correlation between HAPPINESS and PSH, with the color of each bubble specific to the country's political ideology. I just don't know where to begin and I was hoping someone on this website could help me!

here is the code I have so far

ggplot(myData, aes(x=PSH, y=HAPPINESS, label=COUNTRY))+
geom_point(aes(size=1, fill = IDE), shape=21)+ 
scale_size_area(max_size = 22)+
scale_x_continuous(name="Public Spending on Healthcare", limits=c(0,12))+
scale_y_continuous(name="Happiness Index", limits=c(0,1250))+
geom_text(size=4)+
theme_bw()

but it does not show anything on the chart

Sarah
  • 11
  • 2

1 Answers1

1

You can first create a scatter plot with ggplot. Sample as below.

g1 <- ggplot(myData,aes(x=PSH,y=HAPPINESS)) + geom_point(aes(color=IDE))
g1

Then you can add a smooth line

g1 + geom_smooth()