I am trying to overlay two variables on a same figure with ggplot2, so I use melt to get the data in the correct format and then use the following:
Locations <- c("USA","UK","Spain")
vals_1 <- c(44,6,76)
vals_2 <- c(0.2,0.9,4.1)
dat <- data.frame(Locs = Locations,
method_1 = vals_1,
method_2 = vals_2)
dat2 <- melt(dat,id = "Locs")
ggplot(data = dat2,
aes(x = Locs, y = value, colour = variable))
but this generates an error. Why does it state that there are no layers?
Is this to do with the class of dat2[,1] and dat2[,2] being a factor? If so, what should it be changed to? I would like the graph to show the string in dat2[,1] on the xaxis and both the variables shown in the plot. Could someone point me in the right direction?
Amend:
After adding
geom_line()
to get
ggplot(data = dat2,
aes(x = Locs, y = value, colour = variable)) +
geom_line()
I receive the following error geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?