Aligning title in ggplot2

0 votes

I am working with the iris data-set to plot 'Sepal.Length vs Petal.Length'

ggplot(data=iris,aes(x=Sepal.Length,y=Petal.Length))+geom_point()+ggtitle("Sepal.Length vs Petal.Length")

image

Now, by default the title is left aligned, how can i center align the title?

Apr 27, 2018 in Data Analytics by nirvana
• 3,040 points
459 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

You can use the theme layer to center align the title. Below is the command solves your problem:

ggplot(data=iris,aes(x=Sepal.Length,y=Petal.Length))+geom_point()+ggtitle("Sepal.Length vs Petal.Length")+theme(plot.title = element_text(hjust = 0.5))

image

You can also change other parameters of the title such as font color and font style:

ggplot(data=iris,aes(x=Sepal.Length,y=Petal.Length))+geom_point()+ggtitle("Sepal.Length vs Petal.Length")+theme(plot.title = element_text(hjust = 0.5,colour = "blue",face = "bold.italic"))
image
answered Apr 27, 2018 by Bharani
• 4,550 points

Related Questions In Data Analytics

0 votes
1 answer

How to change fill color in each facet using ggplot2?

You can map the facetting variable to ...READ MORE

answered May 8, 2018 in Data Analytics by kappa3010
• 2,010 points
1,438 views
0 votes
1 answer

How to stack scatterplot in ggplot2?

Use melt() to reshape your data with total as a factor ...READ MORE

answered May 8, 2018 in Data Analytics by darklord
• 6,140 points
98 views
0 votes
1 answer

How can I add x and y axis labels in ggplot2 ?

# Load a dataset(to work with) # We’ll ...READ MORE

answered May 16, 2018 in Data Analytics by zombie
• 3,690 points
52 views
0 votes
1 answer

How can I change font size and direction of axes text in ggplot2 ?

You can try theme(): Library(ggplot2) a <- data.frame(x=gl(10, 1, ...READ MORE

answered May 30, 2018 in Data Analytics by zombie
• 3,690 points
83 views
0 votes
1 answer

How to plot side-by-side Plots with ggplot2 in R?

By Using gridExtra library we can easily ...READ MORE

answered Apr 16, 2018 in Data Analytics by DeepCoder786
• 1,700 points
916 views
0 votes
1 answer

Showing percentage instead of counts in a bar plot - ggplot2 - R

Load the 'scales' package first, which gives ...READ MORE

answered May 28, 2018 in Data Analytics by Bharani
• 4,550 points
892 views
0 votes
1 answer

Making a ggplot2 plot without any legends,axes or axis labels

The below command will give you the ...READ MORE

answered May 29, 2018 in Data Analytics by Bharani
• 4,550 points
28 views
0 votes
1 answer

Removing outliers from a box-plot - ggplot2 - R

You just have to add 'outlier.shape=NA' inside ...READ MORE

answered May 31, 2018 in Data Analytics by Bharani
• 4,550 points
1,446 views
0 votes
10 answers

Changing the legend title in ggplot

Example : p <- ggplot(mtcars, aes(mpg, wt, colour ...READ MORE

answered Dec 10, 2018 in Data Analytics by Rajni
3,442 views
0 votes
1 answer

Changing the order of bars in a bar-plot - ggplot2 - R

You can use the scale_x_discrete() function with ...READ MORE

answered May 28, 2018 in Data Analytics by Bharani
• 4,550 points
1,252 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.