r - xlim not working for discrete values [ggplot2] -
i'm trying set xlim , ylim in ggplot put using below:
ylim=c(0, 1.5) + xlim=c(0,100) +
or
coord_cartesian(xlim = c(0, 100), ylim = (0,1.5)) +
seems throw error:
error in scale_x_discrete(breaks = c(0, 50, 100), labels = c(0, : non-numeric argument binary operator
is because i'm using discrete scale x? using numeric y.
using
scale_y_continuous(limits = c(0, 1.5)) +
seems work gives error:
warning message: removed 2 rows containing missing values (geom_path).
any suggestions on can try?
full code:
cfr <- ggplot(sn, aes(x = mmad,y = fr, group=plan, colour = plan)) + geom_line(size=0.5) + #scale_y_continuous(limits = c(0, 1.5)) + scale_x_discrete(breaks = c(0,50,100), labels= c(0,50,100)) + labs(x = "mmad",y = "%")
p.s.
without putting axis limits in, above code worked without problem
i'm not sure, guess discrete scales accept characters limit-parameters, each character representing factor level (see http://docs.ggplot2.org/0.9.3.1/discrete_scale.html).
df <- data.frame(x=sample(1:3, 10, replace=true), y=sample(20:30, 10, replace=true)) df$x <- as.factor(df$x) cfr <- ggplot(df, aes(x = x,y = y)) + geom_line(size=0.5) + scale_x_discrete(breaks = c(0,50,100), labels= c(0,50,100), limits=c("1", "2", "3")) + labs(x = "mmad",y = "%")
works me... (see limits
parameter in scale_x_discrete).
Comments
Post a Comment