Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Change theme(title=...) to labs(title=...)

  • Loading branch information...
commit 4f5b5f61151a4b34b4a6d673791914742289ebde 1 parent 6661a5b
@wch wch authored
View
2  R/coord-polar.r
@@ -38,7 +38,7 @@
#' geom_bar(width = 1) +
#' scale_fill_manual(values = c("red", "yellow")) +
#' coord_polar("y", start=pi / 3) +
-#' theme(title = "Pac man")
+#' labs(title = "Pac man")
#'
#' # Windrose + doughnut plot
#' movies$rrating <- cut_interval(movies$rating, length = 1)
View
9 R/labels.r
@@ -20,9 +20,11 @@ update_labels <- function(p, labels) {
#' @export
#' @examples
#' p <- qplot(mpg, wt, data = mtcars)
+#' p + labs(title = "New plot title")
#' p + labs(x = "New x label")
#' p + xlab("New x label")
#' p + ylab("New y label")
+#' p + ggtitle("New plot title")
#'
#' # This should work indepdendently of other functions that modify the
#' # the scale names
@@ -34,7 +36,7 @@ update_labels <- function(p, labels) {
#' p + labs(colour = "Cylinders")
#'
#' # Can also pass in a list, if that is more convenient
-#' p + labs(list(x = "X", y = "Y"))
+#' p + labs(list(title = "Title", x = "X", y = "Y"))
labs <- function(...) {
args <- list(...)
if (is.list(args[[1]])) args <- args[[1]]
@@ -52,6 +54,11 @@ xlab <- function(label) {
ylab <- function(label) {
labs(y = label)
}
+#' @rdname labs
+#' @export
+ggtitle <- function(label) {
+ labs(title = label)
+}
# Convert aesthetic mapping into text labels
make_labels <- function(mapping) {
View
4 R/plot-render.r
@@ -131,9 +131,9 @@ ggplot_gtable <- function(data) {
}
# Title
- title <- element_render(theme, "plot.title", plot$options$title)
+ title <- element_render(theme, "plot.title", plot$options$label$title)
title_height <- grobHeight(title) +
- if (is.null(plot$options$title)) unit(0, "lines") else unit(0.5, "lines")
+ if (is.null(plot$options$label$title)) unit(0, "lines") else unit(0.5, "lines")
pans <- subset(plot_table$layout, grepl("^panel", name))
View
3  R/theme-elements.r
@@ -295,6 +295,5 @@ el_def <- function(class = NULL, inherits = NULL, description = NULL) {
plot.background = el_def("element_rect", "rect"),
plot.title = el_def("element_text", "text.title"),
- plot.margin = el_def("unit"),
- title = el_def("character")
+ plot.margin = el_def("unit")
)
View
16 R/theme.r
@@ -111,10 +111,8 @@ print.theme <- function(x, ...) str(x)
#' # Or
#' p + labs(x = "Vehicle Weight", y = "Miles per Gallon")
#'
-#' # Add a title to the plot
-#' p + theme(title = "Vehicle Weight-Gas Mileage Relationship")
#' # Change title appearance
-#' p <- p + theme(title = "Vehicle Weight-Gas Mileage Relationship")
+#' p <- p + labs(title = "Vehicle Weight-Gas Mileage Relationship")
#' p + theme(plot.title = element_text(size = 20))
#' p + theme(plot.title = element_text(size = 20, colour = "Blue"))
#'
@@ -182,7 +180,17 @@ print.theme <- function(x, ...) str(x)
#' k + theme(panel.margin = unit(0, "lines"))
#' }
theme <- function(...) {
- structure(list(...), class="theme")
+ # Add check for deprecated elements
+ extra <- NULL
+ elements <- list(...)
+ if (!is.null(elements[["title"]])) {
+ # This is kind of a hack, but fortunately it will be removed in future versions
+ warning('Setting the plot title with theme(title="...") is deprecated.',
+ ' Use labs(title="...") or ggtitle("...") instead.')
+ elements$labels <- labs(title = elements[["title"]])
+ }
+
+ structure(elements, class="theme")
}
View
2  R/translate-qplot-base.r
@@ -140,6 +140,6 @@
#' # by box() can be controlled in a similar way by the panel.background and
#' # plot.background theme elements. Instead of using title(), the plot title is
#' # set with the title option. See ?theme for more theme elements.
-#' last_plot() + theme(title = "My Plot Title")
+#' last_plot() + labs(title = "My Plot Title")
#' }
NULL
View
2  R/translate-qplot-ggplot.r
@@ -78,5 +78,5 @@
#' # qplot() recognises the same options as plot does, and converts them to their
#' # ggplot2 equivalents. See ?theme for more on ggplot options
#' # qplot(x, y, data = data, main="title", asp = 1)
-#' # ggplot(data, aes(x, y)) + geom_point() + theme(title = "title", aspect.ratio = 1)
+#' # ggplot(data, aes(x, y)) + geom_point() + labs(title = "title") + theme(aspect.ratio = 1)
NULL
View
3  visual_test/guide-position.r
@@ -1,6 +1,7 @@
vcontext("guide-position")
-p1 <- ggplot(mtcars, aes(mpg, disp, colour=cyl)) + geom_point() + theme(title = "title of plot", axis.text.x = element_text(angle = 90)) +
+p1 <- ggplot(mtcars, aes(mpg, disp, colour=cyl)) + geom_point() + labs(title = "title of plot") +
+ theme(axis.text.x = element_text(angle = 90)) +
scale_x_continuous(breaks = mean(mtcars$mpg), labels = "very very long long axis label") +
scale_y_continuous(breaks = mean(mtcars$disp), labels = "very very long long axis label")
Please sign in to comment.
Something went wrong with that request. Please try again.