0

我能够正确地制作绘图,但我想增加线条大小以使绘图更具可读性。当我在 geom_line 中尝试尺寸时,我的线条变得超级胖。我在数据框“数据”中有三个时间序列变量(x,y,z),我想在 y 轴上绘制它们,它们的长度不同,这意味着这些图在不同的时间开始。如何在不使它们变大的情况下更改线条的大小?

P_comp <- ggplot(data, aes(x=Date))+
  geom_line(aes(y = x, colour = "green"))+
  geom_line(aes(y = y, colour = "darkred"))+
  geom_line(aes(y = z, colour = "steelblue"))+
  theme_ipsum()+
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())+
  theme(text = element_text(family = "serif"))+
  xlab("Time") + ylab("Value") +
  ggtitle("EPU Indices")+
  theme(plot.title = element_text(hjust = 0.5, family = "serif", face = "plain", size = 16))+
  theme(axis.title.x = element_text(hjust = 0.5, family = "serif", size = 12, face = "plain"))+
  theme(axis.title.y = element_text(hjust = 0.5, family = "serif", size = 12, face = "plain"))
P_comp

这是不使用 size 参数的情节

这是在其中一个 geom_lines 中输入 size= 1 时的图

4

2 回答 2

3

您的代码片段未在此处显示,但听起来您size = 1aes()语句中进行设置。这将添加一个名为“1”的尺寸美学并自动为其分配尺寸。

试试这个:geom_line(aes(y = x, colour = "green"), size = 1)

于 2020-10-02T09:45:03.897 回答
0

scale_size_*可以使用其中一种比例设置线宽。在下面的示例中,我将使用scale_size_manual.
线条大小将设置为分类变量的每个级别一个值,"group

在第一个示例中,线条大小设置为 values 1:3,使线条更粗。

library(ggplot2)

ggplot(df1, aes(Date, y, color = group)) +
  geom_line(aes(size = group)) +
  scale_size_manual(values = 1:3) +
  theme_bw()

在此处输入图像描述

现在让线条更细。其余的情节是一样的。

ggplot(df1, aes(Date, y, color = group)) +
  geom_line(aes(size = group)) +
  scale_size_manual(values = (1:3)/5) +
  theme_bw()

在此处输入图像描述

数据

df1 <- iris[4:5]
df1$Date <- rep(seq(Sys.Date() - 49, Sys.Date(), by = "day"), 3)
names(df1)[1:2] <- c("y", "group")
于 2020-10-02T09:48:24.850 回答