I have some questions about legends and axis in ggplot2.
- I want to plot two lines in the same graph and want to add a legend (group 1 and group 2) with the used linetypes and points.
- Is there a possibility, to start the X-axis (R) at the origin? I know that a bar chart would actually be the correct choice, but I want to use a line chart for content reasons. There is my code:
set.seed(1234)
data <- data.frame(
X = sample(1:6),
Y = sample(1:6))
dim=c("R","I","A","S","E","C")
datadim<-cbind(dim,data)
datadim$dim <- factor(datadim$dim,levels = c("R","I","A","S","E","C"))
#Plot erzeugen
ggplot(data=datadim, aes(x=dim, group=2))+
geom_line(aes(y=X),linetype=1, size=1)+
geom_point(aes(y=X), size=2, shape=1)+
geom_line(aes(y=Y),linetype=2, size=1)+
geom_point(aes(y=Y), size=2, shape=4)+
labs(x="", y="Int")+
scale_y_continuous(limits=c(0, 6), breaks = seq(0, 6, by=0.5))+
geom_rangeframe()+
theme_classic()
Thank you very much!