0
votes

Would you mind taking a look at this?

https://docs.google.com/spreadsheets/d/14vVWxhaQynPmnAsZHlrkkdeJTt0XlDzHc5JSd4DNF-Y/edit?usp=sharing

I have three variables; first one for Year from 2000 - 2017, second one for each country's GDP over the 2000-2017 and the third for soccer ranking over the 2000-2017.

I would like to draw one giant scatter plot; Year 2000-2017 on X-axis, Rank reversed starting from 200 on bottom to 1 on top on Y-axis while each scatter point size vary with GDP size.

All I can come up with is plotting a scatter plot for one country only:

rank <- read.csv("Test1.csv", sep=",", header=TRUE)

library(ggplot2)

qplot(Year, Rank , data = rank, size = Aruba)

But I would like to fit all the countries into one scatter plot while y-axis being reversed and draw a linear regression of all scatter points if possible.

Can someone help me on this?

1
You need to reorganize your data to long form. Paste some reproducible data please.Bing
Welcome to Stack Overflow! Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use str(), head() or screenshot)? You can use the reprex and datapasta packages to assist you with that. See also Help me Help you & How to make a great R reproducible example?Tung
It's definitely preferred if you can post a representative sample of data in your question, such as with dput or one of the packages suggested above, rather than linking folks to a third-party downloadcamille

1 Answers

0
votes

I am not sure how you want the regression done. But here is the graph.

Edits: Because there is a country named "Rankmibia" which I never heard of, select by prefix won't work, I used position this time.

rank <- read.csv("Test1.csv", sep=",", header=TRUE)

library(tidyr)
library(ggplot2)
library(dplyr)

r=rank %>% select(seq(3,ncol(rank),2)) %>% gather(id,rank)
g=rank %>% select(1,seq(2,ncol(rank),2)) %>% gather(country,GDP,-Year)

df=cbind(g, rank=r$rank)
g=qplot(Year, rank , data = df, size = GDP, color=country)+scale_y_reverse()
ggsave("fig.png",g,width=40,height=20)

enter image description here