r - ggplot overlay plot error, no layers in plot -
i trying overlay 2 variables on same figure ggplot2, use melt data in correct format , use 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 generates error. why state there no layers?
is class of dat2[,1] , dat2[,2] being factor? if so, should changed to? graph show string in dat2[,1] on xaxis , both variables shown in plot. point me in right direction?
amend:
after adding
geom_line()
to get
ggplot(data = dat2, aes(x = locs, y = value, colour = variable)) + geom_line() i receive following error geom_path: each group consist of 1 observation. need adjust group aesthetic?
you have tell ggplot() points connect lines. done adding group=variable inside aes().
ggplot(data = dat2, aes(x = locs, y = value, colour = variable,group=variable)) + geom_line()
Comments
Post a Comment