Adjust geom_point size so large values are plotted, but do not appear larger in ggplot2?
The issue I am having is that I would like the points above a certain threshold (=<25) to not produce points larger than the set scale. These larger points still need to be displayed, and cannot be excluded:
d=data.frame(y=c(1,2,6,4,4,6,7,8),
x=c(8,4,7,5,4,9,2,3),
coverage=c(0,6,9,88,25,22,17,100),
col=c(0,.25,.50,.76,.80,1.00,.11,.34)
)
ggplot() +
scale_size(range = c(0, 13),
breaks = c(0, 5, 10, 20, 25),
labels = c("0", "5", "10", "20", "25+"),
guide = "legend"
) +
geom_point(data = d, mapping = aes(x = x, y = y, color = col, size = coverage)) +
labs(title = "geom_point")
In the above sample code I have two points which have a "coverage" larger than 25+ and are outside of the scale. I would like these points to appear the same size as the 25+ threshold.
r ggplot2 plot
add a comment |
The issue I am having is that I would like the points above a certain threshold (=<25) to not produce points larger than the set scale. These larger points still need to be displayed, and cannot be excluded:
d=data.frame(y=c(1,2,6,4,4,6,7,8),
x=c(8,4,7,5,4,9,2,3),
coverage=c(0,6,9,88,25,22,17,100),
col=c(0,.25,.50,.76,.80,1.00,.11,.34)
)
ggplot() +
scale_size(range = c(0, 13),
breaks = c(0, 5, 10, 20, 25),
labels = c("0", "5", "10", "20", "25+"),
guide = "legend"
) +
geom_point(data = d, mapping = aes(x = x, y = y, color = col, size = coverage)) +
labs(title = "geom_point")
In the above sample code I have two points which have a "coverage" larger than 25+ and are outside of the scale. I would like these points to appear the same size as the 25+ threshold.
r ggplot2 plot
1
The best option is likely to make a new variable that truncatescoverage
at 25 and use that for your size aesthetic.
– zack
Jan 2 at 22:21
add a comment |
The issue I am having is that I would like the points above a certain threshold (=<25) to not produce points larger than the set scale. These larger points still need to be displayed, and cannot be excluded:
d=data.frame(y=c(1,2,6,4,4,6,7,8),
x=c(8,4,7,5,4,9,2,3),
coverage=c(0,6,9,88,25,22,17,100),
col=c(0,.25,.50,.76,.80,1.00,.11,.34)
)
ggplot() +
scale_size(range = c(0, 13),
breaks = c(0, 5, 10, 20, 25),
labels = c("0", "5", "10", "20", "25+"),
guide = "legend"
) +
geom_point(data = d, mapping = aes(x = x, y = y, color = col, size = coverage)) +
labs(title = "geom_point")
In the above sample code I have two points which have a "coverage" larger than 25+ and are outside of the scale. I would like these points to appear the same size as the 25+ threshold.
r ggplot2 plot
The issue I am having is that I would like the points above a certain threshold (=<25) to not produce points larger than the set scale. These larger points still need to be displayed, and cannot be excluded:
d=data.frame(y=c(1,2,6,4,4,6,7,8),
x=c(8,4,7,5,4,9,2,3),
coverage=c(0,6,9,88,25,22,17,100),
col=c(0,.25,.50,.76,.80,1.00,.11,.34)
)
ggplot() +
scale_size(range = c(0, 13),
breaks = c(0, 5, 10, 20, 25),
labels = c("0", "5", "10", "20", "25+"),
guide = "legend"
) +
geom_point(data = d, mapping = aes(x = x, y = y, color = col, size = coverage)) +
labs(title = "geom_point")
In the above sample code I have two points which have a "coverage" larger than 25+ and are outside of the scale. I would like these points to appear the same size as the 25+ threshold.
r ggplot2 plot
r ggplot2 plot
edited Jan 3 at 2:06


Z.Lin
13.3k22239
13.3k22239
asked Jan 2 at 22:18
Wealthy Oil TycoonWealthy Oil Tycoon
111
111
1
The best option is likely to make a new variable that truncatescoverage
at 25 and use that for your size aesthetic.
– zack
Jan 2 at 22:21
add a comment |
1
The best option is likely to make a new variable that truncatescoverage
at 25 and use that for your size aesthetic.
– zack
Jan 2 at 22:21
1
1
The best option is likely to make a new variable that truncates
coverage
at 25 and use that for your size aesthetic.– zack
Jan 2 at 22:21
The best option is likely to make a new variable that truncates
coverage
at 25 and use that for your size aesthetic.– zack
Jan 2 at 22:21
add a comment |
2 Answers
2
active
oldest
votes
I think this is what you're looking for:
d %>%
mutate(coverage_trunc = pmin(coverage, 25)) %>%
ggplot() +
geom_point(mapping=aes(x=x, y=y, color=col, size=coverage_trunc)) +
labs(title="geom_point") +
scale_size(range=c(0,13),
breaks=c(0,5,10,20,25),
labels=c("0","5","10","20","25+"),
name = "Coverage Truncated",
guide="legend")
This is exactly what I was looking for. Thank you so much!
– Wealthy Oil Tycoon
Jan 2 at 23:38
add a comment |
A ggplot
only solution is to set the scale limits, and define the out of bounds behavior (oob
) correctly. For size, one can use this scale:
ggplot(d, aes(x, y, color = col, size = coverage)) +
geom_point() +
scale_size_area(
max_size = 13,
breaks = c(0,5,10,20,25),
labels = c("0","5","10","20","25+"),
guide = "legend",
limits = c(0, 25),
oob = scales::squish
)
add a comment |
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2f54013902%2fadjust-geom-point-size-so-large-values-are-plotted-but-do-not-appear-larger-in%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think this is what you're looking for:
d %>%
mutate(coverage_trunc = pmin(coverage, 25)) %>%
ggplot() +
geom_point(mapping=aes(x=x, y=y, color=col, size=coverage_trunc)) +
labs(title="geom_point") +
scale_size(range=c(0,13),
breaks=c(0,5,10,20,25),
labels=c("0","5","10","20","25+"),
name = "Coverage Truncated",
guide="legend")
This is exactly what I was looking for. Thank you so much!
– Wealthy Oil Tycoon
Jan 2 at 23:38
add a comment |
I think this is what you're looking for:
d %>%
mutate(coverage_trunc = pmin(coverage, 25)) %>%
ggplot() +
geom_point(mapping=aes(x=x, y=y, color=col, size=coverage_trunc)) +
labs(title="geom_point") +
scale_size(range=c(0,13),
breaks=c(0,5,10,20,25),
labels=c("0","5","10","20","25+"),
name = "Coverage Truncated",
guide="legend")
This is exactly what I was looking for. Thank you so much!
– Wealthy Oil Tycoon
Jan 2 at 23:38
add a comment |
I think this is what you're looking for:
d %>%
mutate(coverage_trunc = pmin(coverage, 25)) %>%
ggplot() +
geom_point(mapping=aes(x=x, y=y, color=col, size=coverage_trunc)) +
labs(title="geom_point") +
scale_size(range=c(0,13),
breaks=c(0,5,10,20,25),
labels=c("0","5","10","20","25+"),
name = "Coverage Truncated",
guide="legend")
I think this is what you're looking for:
d %>%
mutate(coverage_trunc = pmin(coverage, 25)) %>%
ggplot() +
geom_point(mapping=aes(x=x, y=y, color=col, size=coverage_trunc)) +
labs(title="geom_point") +
scale_size(range=c(0,13),
breaks=c(0,5,10,20,25),
labels=c("0","5","10","20","25+"),
name = "Coverage Truncated",
guide="legend")
answered Jan 2 at 22:31
zackzack
3,3941322
3,3941322
This is exactly what I was looking for. Thank you so much!
– Wealthy Oil Tycoon
Jan 2 at 23:38
add a comment |
This is exactly what I was looking for. Thank you so much!
– Wealthy Oil Tycoon
Jan 2 at 23:38
This is exactly what I was looking for. Thank you so much!
– Wealthy Oil Tycoon
Jan 2 at 23:38
This is exactly what I was looking for. Thank you so much!
– Wealthy Oil Tycoon
Jan 2 at 23:38
add a comment |
A ggplot
only solution is to set the scale limits, and define the out of bounds behavior (oob
) correctly. For size, one can use this scale:
ggplot(d, aes(x, y, color = col, size = coverage)) +
geom_point() +
scale_size_area(
max_size = 13,
breaks = c(0,5,10,20,25),
labels = c("0","5","10","20","25+"),
guide = "legend",
limits = c(0, 25),
oob = scales::squish
)
add a comment |
A ggplot
only solution is to set the scale limits, and define the out of bounds behavior (oob
) correctly. For size, one can use this scale:
ggplot(d, aes(x, y, color = col, size = coverage)) +
geom_point() +
scale_size_area(
max_size = 13,
breaks = c(0,5,10,20,25),
labels = c("0","5","10","20","25+"),
guide = "legend",
limits = c(0, 25),
oob = scales::squish
)
add a comment |
A ggplot
only solution is to set the scale limits, and define the out of bounds behavior (oob
) correctly. For size, one can use this scale:
ggplot(d, aes(x, y, color = col, size = coverage)) +
geom_point() +
scale_size_area(
max_size = 13,
breaks = c(0,5,10,20,25),
labels = c("0","5","10","20","25+"),
guide = "legend",
limits = c(0, 25),
oob = scales::squish
)
A ggplot
only solution is to set the scale limits, and define the out of bounds behavior (oob
) correctly. For size, one can use this scale:
ggplot(d, aes(x, y, color = col, size = coverage)) +
geom_point() +
scale_size_area(
max_size = 13,
breaks = c(0,5,10,20,25),
labels = c("0","5","10","20","25+"),
guide = "legend",
limits = c(0, 25),
oob = scales::squish
)
answered Jan 3 at 0:23


AxemanAxeman
19.3k54559
19.3k54559
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f54013902%2fadjust-geom-point-size-so-large-values-are-plotted-but-do-not-appear-larger-in%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
1
The best option is likely to make a new variable that truncates
coverage
at 25 and use that for your size aesthetic.– zack
Jan 2 at 22:21