ggplot 2 changing X and Y scale

Hi everyone im trying to change the y scale and used the following code chunk
ggplot(data=Merged_Dataset, aes(x=MintuesAsleep, y=TimeInBed))+
geom_point() + geom_smooth() +labs(title="Mintues Asleep vs Time In Bed")+
xlim=c(0,200)+
ylim=c(0,200)

and got error message :"Error in c(0, 200) + ylim = c(100, 150) :
target of assignment expands to non-language object"

im simply trying to change the y scale in increments of 200 instead of 250

Did you run ?xlim to check the documentation?

Hi @Josh_Rivera , see this example for help you

set.seed(321)
Merged_Dataset <- data.frame(
  MintuesAsleep = rnorm(100, mean = 150, sd = 50),
  TimeInBed = rnorm(100, mean = 200, sd = 50)
)

ggplot(data = Merged_Dataset, aes(x = MintuesAsleep, y = TimeInBed)) +
  geom_point() +
  geom_smooth() 

ggplot(data = Merged_Dataset, aes(x = MintuesAsleep, y = TimeInBed)) +
  geom_point() +
  geom_smooth() +
  scale_y_continuous(breaks = seq(0, 200, by = 50)) +
  coord_cartesian(ylim = c(0, 200))  
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.