scale_x_discrete(..., expand = waiver()) scale_y_discrete(..., expand = waiver())
name,
breaks, labels, na.value,
limits and guide. See
discrete_scale for more detailsYou can use continuous positions even with a discrete position scale - this allows you (e.g.) to place labels between bars in a bar chart. Continuous positions are numeric values starting at one for the first level, and increasing by one for each level (i.e. the labels are placed at integer positions). This is what allows jittering to work.
qplot(cut, data=diamonds, stat="bin")
qplot(cut, data=diamonds, geom="bar")
# The discrete position scale is added automatically whenever you # have a discrete position. (d <- qplot(cut, clarity, data=subset(diamonds, carat > 1), geom="jitter"))
d + scale_x_discrete("Cut")
d + scale_x_discrete("Cut", labels = c("Fair" = "F","Good" = "G", "Very Good" = "VG","Perfect" = "P","Ideal" = "I"))
d + scale_y_discrete("Clarity")
d + scale_x_discrete("Cut") + scale_y_discrete("Clarity")
# Use limits to adjust the which levels (and in what order) # are displayed d + scale_x_discrete(limits=c("Fair","Ideal"))Warning message: Removed 11189 rows containing missing values (geom_point).
# you can also use the short hand functions xlim and ylim d + xlim("Fair","Ideal", "Good")Warning message: Removed 9610 rows containing missing values (geom_point).
d + ylim("I1", "IF")Warning message: Removed 16770 rows containing missing values (geom_point).
# See ?reorder to reorder based on the values of another variable qplot(manufacturer, cty, data=mpg)
qplot(reorder(manufacturer, cty), cty, data=mpg)
qplot(reorder(manufacturer, displ), cty, data=mpg)
# Use abbreviate as a formatter to reduce long names qplot(reorder(manufacturer, cty), cty, data=mpg) + scale_x_discrete(labels = abbreviate)
scale_x_continuous,
scale_x_date,
scale_x_datetime,
scale_x_log10,
scale_x_reverse,
scale_x_sqrt,
scale_y_continuous,
scale_y_date,
scale_y_datetime,
scale_y_log10,
scale_y_reverse, scale_y_sqrt