【问题标题】:Trying to get a smoother line on a ggplot graph in R试图在 R 中的 ggplot 图上获得更平滑的线条
【发布时间】:2020-05-16 21:28:12
【问题描述】:

所以我有一个折线图,我想让它看起来比现在更平滑一些。现在,图上有一堆锯齿状的边缘,我希望它弯曲一点。我尝试使用 geom_smooth ,但这使得最大的 y 值接近 150,而它应该接近 230(如图所示)。知道如何使这个折线图更平滑一点吗?

library(tidyverse)
library(ggplot2)
library(ggrepel)
library(dplyr)

source("https://raw.githubusercontent.com/samhoppen/2020_FF_Analysis/master/Functions/fpros_scrape_projections.R")
source("https://raw.githubusercontent.com/samhoppen/2020_FF_Analysis/master/Functions/set_vor.R")

position <- c("qb", "rb", "wr", "te")
week <- "draft"

crossing(position, week)

projections <- crossing(position = position, week = week) %>% 
  pmap_dfr(scrape_projections) %>%
  mutate_at(vars(pass_yds, rush_yds, rec_yds), str_remove, ",") %>% 
  mutate_at(vars(pass_att:rec_tds), as.numeric) %>%
  mutate_at(vars(team:position), as.factor) %>% 
  select(-c("week")) %>% 
  as_tibble()

default_baseline <- c(QB = 15, RB =72, WR = 90, TE = 30, K = 6)

vor_table <- set_vor(projections,
                             vor_baseline = default_baseline,
                             vor_var = "fpts")
ggplot() +
  geom_line(data = vor_table,
              aes(x = fpts_rank, y = fpts_vor))

【问题讨论】:

  • ggplot(data = vor_table, aes(x = fpts_rank, y = fpts_vor)) + geom_line() + geom_smooth(method = "gam", formula = y ~ s(x, bs = "tp", k=13), se=F, color="red")怎么样?

标签: r ggplot2 graph charts


【解决方案1】:

这可能有效:

ggplot()+  
stat_smooth(data = vor_table, aes(x = fpts_rank, y = fpts_vor), 
            se = F, method = "lm", formula = y ~ poly(x, 10))

【讨论】:

    猜你喜欢
    • 2020-08-10
    • 1970-01-01
    • 1970-01-01
    • 2023-01-12
    • 1970-01-01
    • 2018-06-17
    • 1970-01-01
    • 2018-10-12
    • 2016-09-29
    相关资源
    最近更新 更多