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,020 points
73 views

1 answer to this question.

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

0 votes
0 answers

Arrange the order of axis elements in ggplot

How to arrange the order of axis ...READ MORE

Jul 17 in Data Analytics by likitha
17 views
0 votes
1 answer

Change the order of multiple legends in ggplot

Hi Radha, You can change the order of ...READ MORE

answered Jul 24 in Data Analytics by Cherukuri
• 20,950 points
29 views
+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,520 points
3,126 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
• 39,310 points
1,018 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
90 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,020 points
891 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
73 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
64 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
39 views
0 votes
2 answers

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

Hi,  I'm not sure about the command but you ...READ MORE

answered 1 day ago in Data Analytics by Cherukuri
• 20,950 points
2,059 views