简体   繁体   English

我需要帮助在 r 中使用 smooth.spline 进行绘图

[英]I need help plotting using smooth.spline in r

I am using spline.smooth in r and need some help.我在 r 中使用 spline.smooth,需要一些帮助。 Here are my codes:这是我的代码:

my_df_1 <- data.frame(date = seq(as.Date("2020/1/15"), by = "day", length.out = 100),
                      rate = runif(100, min=0, max=0.7),
                      count=sample(2:50, 100, replace = TRUE))

fit <- smooth.spline(my_df_1$date, my_df_1$rate)
plot(my_df_1$date, my_df_1$rate)
lines(fit)

First, I want to change the size of points on plot using column count.首先,我想使用列数更改 plot 上点的大小。 Second, is there a way to plot smooth spline in ggplot?其次,有没有办法在ggplot中让plot平滑样条? Third, how can I format my x-axis for the date.第三,如何格式化日期的 x 轴。 I want to have a day and month in the x-axis.我想在 x 轴上有一天和一个月。 Thanks in advance everyone!提前谢谢大家!

How about this:这个怎么样:

my_df_1 %>% 
  ggplot(aes(x = date, y = rate)) +
  geom_smooth() +
  geom_point(aes(size = count)) +
  scale_x_date(date_labels = "%d-%B")

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

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