Working of ggplot scale_continuous 'expand' argument

0 votes

According to the scale_continuous documentation

A numeric vector of length two giving multiplicative and additive expansion constants. These constants ensure that the data is placed some distance away from the axes. The defaults are c(0.05, 0) for continuous variables, and c(0, 0.6) for discrete variables.

Since they are stated as "expansion constants", they are not actual units.

Can we convert them to some actual units to predict the actual output?

Apr 12, 2018 in Data Analytics by kappa3010
• 2,010 points
54 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

According to the document if you set limits manually, it would be more clear.

Refer below examples to know how it works:

The 1st argument gives expansion equal to multiplication by limit range.

ggplot(mpg, aes(displ, hwy)) +
    geom_point() +
    scale_x_continuous(limits = c(1, 7), expand = c(0.5, 0))
# Right most position will be 7 + (7-1) * 0.5 = 10

The 2nd argument gives the absolute expansion added to both end of the axis:

ggplot(mpg, aes(displ, hwy)) +
    geom_point() +
    scale_x_continuous(limits = c(1, 7), expand = c(0.5, 2))
# Right most position will be 7 + (7-1) * 0.5  + 2 = 12
answered Apr 12, 2018 by DataKing99
• 8,100 points

Related Questions In Data Analytics

+1 vote
3 answers

Problem with installation of Wordcloud in anaconda

Using Anaconda Python 3.6 version For Windows ...READ MORE

answered Aug 7, 2018 in Data Analytics by Priyaj
• 56,140 points
2,143 views
+1 vote
3 answers

Integration of Google Collaboratory with github

You can use SSH protocol to connect ...READ MORE

answered Aug 7, 2018 in Data Analytics by Kalgi
• 36,220 points
857 views
0 votes
1 answer

Finding frequency of observations in R

You can use the "dplyr" package to ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,550 points
53 views
+1 vote
1 answer

Custom Function to replace missing values in a vector with the mean of values

You have missed out on "na.rm=TRUE" inside ...READ MORE

answered Mar 27, 2018 in Data Analytics by Bharani
• 4,550 points
36 views
0 votes
1 answer

Save a plot as image on the disk using R

Consider for both the situations: 1. Image will ...READ MORE

answered Apr 13, 2018 in Data Analytics by darklord
• 6,140 points
51 views
0 votes
1 answer

Plot two variables as lines on the same graph using ggplot

If you have small number of variables, ...READ MORE

answered Apr 17, 2018 in Data Analytics by kappa3010
• 2,010 points
724 views
0 votes
1 answer

R programming: How to compute Euler's number?

The following R statement exp(1) indicates e, and exp(2) represents e^2. This ...READ MORE

answered Dec 28, 2018 by Tyrion anex
• 8,280 points
39 views
0 votes
1 answer

R programming: How to pass variables from a r program to mysql function?

To include the R variables called start.date and end.date, you can use paste to ...READ MORE

answered Dec 28, 2018 in Data Analytics by Tyrion anex
• 8,280 points
55 views
0 votes
1 answer

Find length of string in R

You can try nchar > nchar("fast") [1] 4 > set.seed(10) > ...READ MORE

answered Apr 17, 2018 in Data Analytics by DataKing99
• 8,100 points
30 views
0 votes
1 answer

How to set working directory to source file location in R?

You can try out this solution: this.dir <- ...READ MORE

answered May 3, 2018 in Data Analytics by DataKing99
• 8,100 points
1,657 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.