Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the color of the title in a ggplot

I have been working with this for some time and can't find any reasonable explanation for why the names of my x and y axis are the correct color, but not the title.

p <- ggplot(movies, aes(x=budget, y=rating))+
  geom_point(shape=1) +
  theme(axis.title.x = element_text(colour = "#7F3D17"),
        axis.title.y = element_text(colour = "#7F3D17"),
        axis.title = element_text(colour = "#7F3D17"),
        panel.background = element_rect(fill='#FFD197'),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.border = element_blank()) +
  labs(x="Budget (in millions)", y="Rating", title="Scatterplot of budget vs movies")
p

The scatterplot looks like this (notice that the title is still black):

enter image description here

If anyone could help I would greatly appreciate it.

like image 413
tumultous_rooster Avatar asked Mar 23 '14 09:03

tumultous_rooster


People also ask

How do you change colors in ggplot?

Change colors manually A custom color palettes can be specified using the functions : scale_fill_manual() for box plot, bar plot, violin plot, etc. scale_color_manual() for lines and points.

How do I bold a title in ggplot2?

We can change the appearance text elements of a plot made with ggplot2 using theme element element_text() function. To make both x and y-axis's title text in bold font, we will use axis. title argument to theme() function with element_text(face=”bold”). Note now both x and y axis's title text are in bold font.

What is color in ggplot2?

Default ggplot gradient colorsThe default ggplot2 setting for gradient colors is a continuous blue color. In the following example, we color points according to the variable: Sepal. Length . sp2 <- ggplot(iris, aes(Sepal.Length, Sepal.Width))+ geom_point(aes(color = Sepal.Length))

How do I change labels in R?

To set labels for X and Y axes in R plot, call plot() function and along with the data to be plot, pass required string values for the X and Y axes labels to the “xlab” and “ylab” parameters respectively. By default X-axis label is set to “x”, and Y-axis label is set to “y”.


1 Answers

You are using axis.title = element_text(colour = "#7F3D17") to get the right color for the title. But you should be using plot.title = element_text(colour = "#7F3D17").

With axis.title you define the setting for both axis, whereas with axis.title.x or axis.title.y you define the setting for the x-axis title or y-axis title specifically.

Because you are using the same color for all the titles, you can also use title = element_text(colour = "#7F3D17") which should set the color of the plot title, axis titles and legend title to the same color.

like image 173
Jaap Avatar answered Oct 01 '22 11:10

Jaap