Reputation: 27
I'm trying to make a line plot of 3-point makes for Steph so far this season but the spacing of the y axis ticks are way too close together. Line graph. I'm sure there's a relatively easy fix for this. I'm also wondering how to label only Game 1 and Game 29 on the x-axis, rather than every single game. I hope this is enough information for an answer, if not let me know! Cheers.
ggplot(data=Top_10, aes(y=Stephen_Curry, x=Game_Number, group=1)) +
geom_line(color="blue") +
geom_point(color="black") +
scale_x_discrete(limits = c("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29")) +
scale_y_continuous(breaks=seq(0,15,1)) +
theme(axis.text.y = element_text(margin = margin(r=5)))
Upvotes: 0
Views: 1010
Reputation: 123783
Without any example data I could only guess what's the reason why the default scaling does not work.
However, based on this random example data set I was able to "replicate" your issue:
library(ggplot2)
set.seed(42)
Top_10 <- data.frame(
Game_Number = factor(1:30, levels = 1:30),
Stephen_Curry = c(sample(0:15, 29, replace = TRUE), 100)
)
ggplot(data=Top_10, aes(y=Stephen_Curry, x=Game_Number, group=1)) +
geom_line(color="blue") +
geom_point(color="black") +
scale_x_discrete(limits = as.character(1:29)) +
scale_y_continuous(breaks=seq(0,15,1)) +
theme(axis.text.y = element_text(margin = margin(r=5)))
#> Warning: Removed 1 row(s) containing missing values (geom_path).
#> Warning: Removed 1 rows containing missing values (geom_point).
To solve this issue you could set limits of the y scale to c(0, 15)
and for your x-axis issue you could set the breaks to c("1", "29")
:
ggplot(data=Top_10, aes(y=Stephen_Curry, x=Game_Number, group=1)) +
geom_line(color="blue") +
geom_point(color="black") +
scale_x_discrete(breaks = c("1", "29"), limits = as.character(1:29)) +
scale_y_continuous(breaks=seq(0,15,1), limits = c(0, 15)) +
theme(axis.text.y = element_text(margin = margin(r=5)))
#> Warning: Removed 1 row(s) containing missing values (geom_path).
#> Warning: Removed 1 rows containing missing values (geom_point).
Upvotes: 1