0

I am a beginner in R and require help in visualizing some data. I am trying to plot the value of HDI of countries from 1990-2017.

My collated data is as such for example:

Country Year HDI
Brunei  1990 0.782
Brunei  1991 0.787
...
Brunei  2017 0.853
...
Cambodia 1990 0.364
...
Cambodia 2017 0.582

The data follows for countries as such. My code is currently as such:

x = ggplot(data=Collated.Data, aes(x=Year, y=HDI)) +
  geom_line(position=position_dodge(width=0.5)) +
  labs(x="Years 1990-2017", y="Value of HDI") +
  ggtitle("HDI of Country over the years") +
  theme(plot.title=element_text(hjust=.5)) +
  geom_text(aes(label=POT$Country), hjust=0, vjust=0)

The code shows this for instance, when I am covering ten countries:

enter image description here

How would I clean this graph and also add the country at the end? Would really appreciate some help on this matter :)

r2evans
  • 141,215
  • 6
  • 77
  • 149
Lesley
  • 13
  • 4

1 Answers1

0

You should provide a reproducible example of the dataset in order we help you at the best.

For your plot, based on your code, I think you should try:

library(ggplot2)
ggplot(data=Collated.Data, aes(x=Year, y=HDI, group = as.factor(Country))) +
  geom_line() +
  labs(x="Years 1990-2017", y="Value of HDI") +
  ggtitle("HDI of Country over the years") +
  theme(plot.title=element_text(hjust=.5)

It should plot the HDI in function of Year for each Country. All Country names and associated colors should appear in the legend and make your plot much more lisible.

I can't provide you an example of the final graphic because I don't have an example of your dataset to work with

dc37
  • 15,840
  • 4
  • 15
  • 32
  • Thank you for your reply! How would I provide a reproducible example of my dataset? I could send a link which includes the dataset. – Lesley Nov 16 '19 at 07:22
  • As it is mention in the link, you should enter `dput(droplevels(Collated.data[1:50,]))`. It should provide the structure of the file for at least two country which is plenty enough to show you how to do it. – dc37 Nov 16 '19 at 14:53