df <- data.frame(age=c(10,10,20,20,25,25,25),veg=c(0,1,0,1,1,0,1))
g=ggplot(data=df,aes(x=age,y=veg))
g=g+stat_summary(fun.y=mean,geom="point")
Points reflect mean of veg at each age, which is what I expected and want to preserve after changing axis limits with the command below.
g=g+ylim(0.2,1)
Changing axis limits with the above command unfortunately causes veg==0 subset to be dropped from the data, yielding
"Warning message: Removed 4 rows containing missing values (stat_summary)"
This is bad because now the data plot (stat_summary mean) omits the veg==0 points. How can this be prevented? I simply want to avoid showing the empty part of the plot- the ordinate from 0 to .2, but not drop the associated data from the stat_summary calculation.
Set y-Axis Limits for Specific AxesCall the tiledlayout function to create a 2-by-1 tiled chart layout. Call the nexttile function to create the axes objects ax1 and ax2 . Plot data into each axes. Then set the y-axis limits for the bottom plot by specifying ax2 as the first input argument to ylim .
matplotlib.pyplot.xlim() Function The xlim() function in pyplot module of matplotlib library is used to get or set the x-limits of the current axes.
xlim([xmin xmax]) sets the axis limits in the current axes to the specified values. xlim('mode') returns the current value of the axis limits mode, which can be either auto (the default) or manual .
you can do that by specifying the coord system:
df <- data.frame(age=c(10,10,20,20,25,25,25),veg=c(0,1,0,1,1,0,1))
g=ggplot(data=df,aes(x=age,y=veg))
g=g+stat_summary(fun.y=mean,geom="point")
g+coord_cartesian(ylim=c(0.2,1)) #do not use +ylim() here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With