简体   繁体   English

在 R ggplot 中调整折线图

[英]adjust line graph in R ggplot

enter image description here在此处输入图像描述

How do you adjust the line graph to avoid so much spare space?.你如何调整折线图以避免这么多的空闲空间?。 Is scale alpha the way to trim the line graph?.缩放 alpha 是修剪折线图的方式吗?

ggplot(cdata) + 
  geom_line(aes(x = Date, y = Value)) +

You can use the scale_x_* and scale_y_* family of functions in ggplot2 to control the scaling and limits of the axes.您可以使用 ggplot2 中的scale_x_*scale_y_*系列函数来控制轴的缩放和限制。

Assuming your cdata$Date is a Date, you can do the following:假设您的cdata$Date是一个日期,您可以执行以下操作:

ggplot(cdata) +
  geom_line(aes(x = Date, y = Value)) +
  scale_x_date(limits = as.Date(c("2020-01-01", "2020-12-31")))

EDIT: If you are looking to scale the y axis, it is continuous, so you could use scale_y_continuous() .编辑:如果你想缩放 y 轴,它是连续的,所以你可以使用scale_y_continuous() There are also other scaling functions available, like scale_*_discrete() , scale_*_log10() , and scale_*_reverse() , depending on the type of values on your axes.还有其他可用的缩放函数,例如scale_*_discrete()scale_*_log10()scale_*_reverse() ,具体取决于轴上值的类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM