Edit
OP , y, expand 0. :
:
set.seed(1)
df <- data.frame(x=1:10,
y=rep(0, 10))
df1 <- data.frame(x=1:10,
y=sample(1:10 , 10, replace=T))
df
df1
, :
plot.zeros <- function(data) {
upper.lim <- ifelse(any(data$y != 0), NA, 1)
print(ggplot(data, aes(x, y)) + geom_point() +
scale_y_continuous(limits = c(0, upper.lim), expand = c(0.01, 0)))
}
plot.zeros(df)
plot.zeros(df1)
, y 1, y- 0. y- , y ββ 0, ggplot. y-max , "else" ifelse - , 1. , expand ylim(0, upper.lim) scale_y_continuous.
, min , expand_limits. , :
df <- data.frame(type=sample(c("a","b"), 20, replace=T),
x=rep(1:10, 2),
y=c(rep(0, 10), sample(1:10 , 10, replace=T)))
df
ggplot(df,aes(x,y)) + geom_point() +
facet_wrap(facets='type', scales="free") +
expand_limits(y=0)

, facet_wrap grid_wrap, :
scale_y_continuous(limits=c(0, max(df$y) * 1.1))