Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to get a smoother line on a ggplot graph in R

So I have a line graph that I want to look a little smoother than it currently is. Right now, there are a bunch of jagged edges on the graph, and I'd like it to curve a bit more. I tried using geom_smooth but that makes the largest y value close to 150 when it should be closer to 230 (as this graph shows). Any idea how to make this line chart a little smoother?

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))
like image 275
Sam Hoppen Avatar asked Dec 06 '25 15:12

Sam Hoppen


1 Answers

This might work:

ggplot()+  
stat_smooth(data = vor_table, aes(x = fpts_rank, y = fpts_vor), 
            se = F, method = "lm", formula = y ~ poly(x, 10))
like image 177
RegressionSquirrel Avatar answered Dec 08 '25 04:12

RegressionSquirrel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!