1

I was following the accepted SO answer to get a line graph with 2 lines over multiple years. Can someone explain what I am doing wrong?

temp<-structure(list(Years = c(1950, 1955, 1960, 1965, 1970, 1975, 
                               1980, 1985, 1990, 1995, 2000, 2002, 2005, 2007, 2009, 2011, 2013, 
                               2015, 2017), X1878_8TF = c(4, 5, 10, 20, 15, 22.5, 80, 70, 47.5, 
                                                          47.5, 65, 125, 125, 150, 150, 140, 140, 160, 170), X7_TF_rev_1878 = c(3, 
                                                                                                                                3, 3, 3.75, 6.5, 17, 65, 57.5, 30, 25, 35, 50, 60, 75, 85, 80, 
                                                                                                                                80, 85, 90)), .Names = c("Years", "X1878_8TF", "X7_TF_rev_1878"
                                                                                                                                ), class = "data.frame", row.names = c(NA, -19L))


df <- melt(temp ,  id.vars = 'Years', variable.name = 'coin_name')
ggplot(df, aes(Years,value)) + 
  geom_line(aes(colour = rainbow(nrow(df))))+
  ggtitle("blah")

This is what I get:

enter image description here

0

1 Answer 1

2

If you just want two lines, I think you want something like:

ggplot(df, aes(Years,value)) +
 geom_line(aes(color = coin_name)) +
 ggtitle("blah")

As you have it, it's trying to make a separate line for every point in your dataset.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.