ggplot histogram as a percent of a specific group

Multi tool use
up vote
2
down vote
favorite
I'm new to R, and have created some simple histograms of a categorical independent variable vs the dependent variable. All facet wrapped according to the categories.
In this case I am using sensitive data, so cannot share any data.
Code
ggplot(merged, aes(CV)) +
geom_histogram(binwidth = 0.5) +
facet_wrap(~BUILDING_AGE, ncol = 2) +
labs(title = "BUILDING_AGE vs CV", y = "Co-efficient of variation", x = "BUILDING_AGE")
Where CV = coefficient of variation (continuous dependent variable) and BUILDING_AGE is the age of the buildings (categorical independent variable - with 7 categories/groups 1-7)
The problem
The problem is that some of the categories have only a small amount of data relative to the other categories, so when I plot the histogram I cannot see the histogram and distribution of the data in these groups with smaller amounts of data.
Ie: the y-axis (counts) is scaled far too large for the categories with very low counts.
Question
Is there a way that each of the facet wrapped windows y-axis could be rescaled according to each of the categories they are displaying?
Hope this makes sense.
Thank you.
r statistics
add a comment |
up vote
2
down vote
favorite
I'm new to R, and have created some simple histograms of a categorical independent variable vs the dependent variable. All facet wrapped according to the categories.
In this case I am using sensitive data, so cannot share any data.
Code
ggplot(merged, aes(CV)) +
geom_histogram(binwidth = 0.5) +
facet_wrap(~BUILDING_AGE, ncol = 2) +
labs(title = "BUILDING_AGE vs CV", y = "Co-efficient of variation", x = "BUILDING_AGE")
Where CV = coefficient of variation (continuous dependent variable) and BUILDING_AGE is the age of the buildings (categorical independent variable - with 7 categories/groups 1-7)
The problem
The problem is that some of the categories have only a small amount of data relative to the other categories, so when I plot the histogram I cannot see the histogram and distribution of the data in these groups with smaller amounts of data.
Ie: the y-axis (counts) is scaled far too large for the categories with very low counts.
Question
Is there a way that each of the facet wrapped windows y-axis could be rescaled according to each of the categories they are displaying?
Hope this makes sense.
Thank you.
r statistics
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'm new to R, and have created some simple histograms of a categorical independent variable vs the dependent variable. All facet wrapped according to the categories.
In this case I am using sensitive data, so cannot share any data.
Code
ggplot(merged, aes(CV)) +
geom_histogram(binwidth = 0.5) +
facet_wrap(~BUILDING_AGE, ncol = 2) +
labs(title = "BUILDING_AGE vs CV", y = "Co-efficient of variation", x = "BUILDING_AGE")
Where CV = coefficient of variation (continuous dependent variable) and BUILDING_AGE is the age of the buildings (categorical independent variable - with 7 categories/groups 1-7)
The problem
The problem is that some of the categories have only a small amount of data relative to the other categories, so when I plot the histogram I cannot see the histogram and distribution of the data in these groups with smaller amounts of data.
Ie: the y-axis (counts) is scaled far too large for the categories with very low counts.
Question
Is there a way that each of the facet wrapped windows y-axis could be rescaled according to each of the categories they are displaying?
Hope this makes sense.
Thank you.
r statistics
I'm new to R, and have created some simple histograms of a categorical independent variable vs the dependent variable. All facet wrapped according to the categories.
In this case I am using sensitive data, so cannot share any data.
Code
ggplot(merged, aes(CV)) +
geom_histogram(binwidth = 0.5) +
facet_wrap(~BUILDING_AGE, ncol = 2) +
labs(title = "BUILDING_AGE vs CV", y = "Co-efficient of variation", x = "BUILDING_AGE")
Where CV = coefficient of variation (continuous dependent variable) and BUILDING_AGE is the age of the buildings (categorical independent variable - with 7 categories/groups 1-7)
The problem
The problem is that some of the categories have only a small amount of data relative to the other categories, so when I plot the histogram I cannot see the histogram and distribution of the data in these groups with smaller amounts of data.
Ie: the y-axis (counts) is scaled far too large for the categories with very low counts.
Question
Is there a way that each of the facet wrapped windows y-axis could be rescaled according to each of the categories they are displaying?
Hope this makes sense.
Thank you.
r statistics
r statistics
asked Nov 10 at 20:27


Cairan Van Rooyen
385
385
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
If you pass 'free'
to the scales
parameter of facet_grid()
or facet_wrap()
, this should address your problem:
facet_wrap(~BUILDING_AGE, ncol = 2, scales = 'free')
Further reading:
https://www.rdocumentation.org/packages/ggplot2/versions/3.0.0/topics/facet_wrap
likely the correct solution. Just make sure to subtitle or caption the title noting the free scales.
– hrbrmstr
Nov 10 at 20:45
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
If you pass 'free'
to the scales
parameter of facet_grid()
or facet_wrap()
, this should address your problem:
facet_wrap(~BUILDING_AGE, ncol = 2, scales = 'free')
Further reading:
https://www.rdocumentation.org/packages/ggplot2/versions/3.0.0/topics/facet_wrap
likely the correct solution. Just make sure to subtitle or caption the title noting the free scales.
– hrbrmstr
Nov 10 at 20:45
add a comment |
up vote
2
down vote
accepted
If you pass 'free'
to the scales
parameter of facet_grid()
or facet_wrap()
, this should address your problem:
facet_wrap(~BUILDING_AGE, ncol = 2, scales = 'free')
Further reading:
https://www.rdocumentation.org/packages/ggplot2/versions/3.0.0/topics/facet_wrap
likely the correct solution. Just make sure to subtitle or caption the title noting the free scales.
– hrbrmstr
Nov 10 at 20:45
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
If you pass 'free'
to the scales
parameter of facet_grid()
or facet_wrap()
, this should address your problem:
facet_wrap(~BUILDING_AGE, ncol = 2, scales = 'free')
Further reading:
https://www.rdocumentation.org/packages/ggplot2/versions/3.0.0/topics/facet_wrap
If you pass 'free'
to the scales
parameter of facet_grid()
or facet_wrap()
, this should address your problem:
facet_wrap(~BUILDING_AGE, ncol = 2, scales = 'free')
Further reading:
https://www.rdocumentation.org/packages/ggplot2/versions/3.0.0/topics/facet_wrap
edited Nov 10 at 20:55
answered Nov 10 at 20:30
12b345b6b78
573115
573115
likely the correct solution. Just make sure to subtitle or caption the title noting the free scales.
– hrbrmstr
Nov 10 at 20:45
add a comment |
likely the correct solution. Just make sure to subtitle or caption the title noting the free scales.
– hrbrmstr
Nov 10 at 20:45
likely the correct solution. Just make sure to subtitle or caption the title noting the free scales.
– hrbrmstr
Nov 10 at 20:45
likely the correct solution. Just make sure to subtitle or caption the title noting the free scales.
– hrbrmstr
Nov 10 at 20:45
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243114%2fggplot-histogram-as-a-percent-of-a-specific-group%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
EU HsyhwVua3,6