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 13, 2018 in Data Analytics by kappa3010
• 2,090 points
2,846 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 13, 2018 by DataKing99
• 8,240 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, 2019 in Data Analytics by likitha
501 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, 2019 in Data Analytics by Cherukuri
• 33,030 points
22,913 views
0 votes
0 answers

Use of ggplot() within another function in R

Using the ggplot2 package, I'm attempting to ...READ MORE

Jun 22, 2022 in Data Analytics by avinash
• 1,840 points

closed Jun 22, 2022 by avinash 322 views
0 votes
0 answers

Understanding output of rbind function when a list is passed as argument

While using R to practise fundamental matrices ...READ MORE

Jun 24, 2022 in Data Analytics by Avinash
• 1,260 points
271 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 14, 2018 in Data Analytics by Sahiti
• 6,370 points
1,810 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,090 points
4,666 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,700 points
1,513 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,700 points
1,014 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,240 points
644 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 Aug 20, 2019 in Data Analytics by Cherukuri
• 33,030 points
13,385 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP