Intermediate Data Visualization with ggplot2
Rick Scavetta
Founder, Scavetta Academy
coord_
coord_cartesian()
coord_cartesian(xlim = ...)
scale_x_continuous(limits = ...)
xlim(...)
iris.smooth <- ggplot(
iris,
aes(x = Sepal.Length,
y = Sepal.Width,
color = Species)
) +
geom_point(alpha = 0.7) +
geom_smooth()
iris.smooth
iris.smooth +
scale_x_continuous(limits = c(4.5, 5.5))
Removed 95 rows containing non-finite values
(stat_smooth).
Removed 95 rows containing missing values
(geom_point).
Original plot
Zoom in with scale_x_continuous()
Part of original data is filtered out!
iris.smooth +
xlim(c(4.5, 5.5))
Removed 95 rows containing non-finite values
(stat_smooth).
Removed 95 rows containing missing values
(geom_point).
iris.smooth +
coord_cartesian(xlim = c(4.5, 5.5))
library(zoo)
sunspots.m <- data.frame(
year = index(sunspot.month),
value = reshape2::melt(sunspot.month)$value)
)
ggplot(sunspots.m, aes(x = year, y = value)) +
geom_line() +
coord_fixed() # default to 1:1 aspect ratio
ggplot(sunspots.m, aes(x = year, y = value)) +
geom_line() +
coord_fixed(0.055)
Intermediate Data Visualization with ggplot2