Home > Net >  How do I get scale_x_continuous to show full range?
How do I get scale_x_continuous to show full range?

Time:10-13

I am trying to plot two functions with ggplot, using the following code:

ggplot()   
  scale_x_continuous(breaks=seq(0, 12, by=1))  
  xlab("Price")   
  ylab("Quantity") 
  geom_function(fun = function(x) 1200-100*x)  
  geom_function(fun = function(x) 100*x) 

plot

CodePudding user response:

Jonas can you post your latest code here? I suspect a simple typo mistake.

You can also define a range for you break like

    breaks = seq(from = 0, to = 12, by = 1.0))

Edit added code:

I get what you want with this code in https://rdrr.io/snippets/

    library(ggplot2)


    ggplot()  
    scale_x_continuous(breaks=seq(0, 12, by=1), limits = c(0, 12))   
    xlab("Price")   
    ylab("Quantity") 
    geom_function(fun = function(x) 1200-100*x)  
    geom_function(fun = function(x) 100*x) 
  • Related