我为心理眼动追踪实验创建了一些线图。因此,我需要具有相同x轴长度的不同图(与图例的大小/名称无关)。 x轴描述了分类数据,对于这种情况,我没有找到任何解决方案。
library(ggplot2)
dat1 <- data.frame(
Bildschirmgröße = factor(c("klein","klein","groß","groß")),
Gehalt = factor(c("niedrig","hoch","niedrig","hoch"),
levels = c("niedrig","hoch")),
Apps = c(15, 24,34,29))
## Plot
lg_51_k <- ggplot(data=dat1, aes(x=Gehalt, y=Apps,
shape=Bildschirmgröße, group=Bildschirmgröße))+
geom_line(aes(color = Bildschirmgröße),size=2)+
theme_classic(base_size=18, )+
theme(axis.line = element_line(colour = "black", size = 2))+
theme(axis.text.x = element_text(size=16, face = "bold"))+
theme(axis.text.y = element_text(size=16, face = "bold"))+
theme(legend.title = element_text(size=18, face="bold"))+
scale_color_manual(values=c("#FF0000", "#0000ff"))+
theme(legend.text = element_text(size=16, face = "bold"))+
theme(axis.title.x = element_text(vjust=-0.5, face = "bold"))+
theme(axis.title.y = element_text(vjust=+1.5, face = "bold"))+
scale_y_continuous(breaks = seq(0, 40, by=4), limits = c(0,40))+
ylab("Anzahl Apps")
## Ausgabe
lg_51_k
THX。
答案 0 :(得分:0)
If I understand you correctly, you want to control the size of the legend. So if you set them big enough, they will all be that one size.
One way to do it is with the legend.size.key
setting, used like this:
library(ggplot2)
library(grid)
dat1 <- data.frame(
Bildschirmgröße = factor(c("klein","klein","groß","groß")),
Gehalt = factor(c("niedrig","hoch","niedrig","hoch"),
levels = c("niedrig","hoch")),
Apps = c(15, 24,34,29))
## Plot
lg_51_k <- ggplot(data=dat1, aes(x=Gehalt, y=Apps,
shape=Bildschirmgröße, group=Bildschirmgröße))+
geom_line(aes(color = Bildschirmgröße),size=2)+
theme_classic(base_size=18, )+
theme(axis.line = element_line(colour = "black", size = 2))+
theme(axis.text.x = element_text(size=16, face = "bold"))+
theme(axis.text.y = element_text(size=16, face = "bold"))+
theme(legend.title = element_text(size=18, face="bold"))+
scale_color_manual(values=c("#FF0000", "#0000ff"))+
theme(legend.text = element_text(size=16, face = "bold"))+
theme(axis.title.x = element_text(vjust=-0.5, face = "bold"))+
theme(axis.title.y = element_text(vjust=+1.5, face = "bold"))+
scale_y_continuous(breaks = seq(0, 40, by=4), limits = c(0,40))+
ylab("Anzahl Apps") +
theme(legend.key.size = unit(6, "cm"))
## Ausgabe
lg_51_k