Set the max value in colormap when using scale_color_viridis
Here is the code:
pic = ggplot(df_2,
aes(x = df_2$X, xend = df_2$X + df_2$dx, y = df_2$Y, yend = df_2$Y + df_2$dy, color = df_2$speedkt)) +
labs(title ="Surface Currents", x = "Longitude", y = "Latitude", colour="Speed (kts)") +
geom_segment(alpha = 0.7, arrow = arrow(length = unit(0.1,"cm"))) + coord_fixed() +
theme(panel.background = element_rect(fill = "transparent",colour = NA), plot.background = element_rect(fill = "transparent",colour = NA)) +
viridis::scale_color_viridis(option = "B", direction = -1)
You can see the color gradient follows the value of df_2$speedkt
. The maximum value of df_2$speedkt
is around 2.6.
So, the maximum value of the colormap in the legend is around 2.8.
But I wish to change the maximum value of the colormap to 4.0.
What I can do?
r ggplot2 viridis
add a comment |
Here is the code:
pic = ggplot(df_2,
aes(x = df_2$X, xend = df_2$X + df_2$dx, y = df_2$Y, yend = df_2$Y + df_2$dy, color = df_2$speedkt)) +
labs(title ="Surface Currents", x = "Longitude", y = "Latitude", colour="Speed (kts)") +
geom_segment(alpha = 0.7, arrow = arrow(length = unit(0.1,"cm"))) + coord_fixed() +
theme(panel.background = element_rect(fill = "transparent",colour = NA), plot.background = element_rect(fill = "transparent",colour = NA)) +
viridis::scale_color_viridis(option = "B", direction = -1)
You can see the color gradient follows the value of df_2$speedkt
. The maximum value of df_2$speedkt
is around 2.6.
So, the maximum value of the colormap in the legend is around 2.8.
But I wish to change the maximum value of the colormap to 4.0.
What I can do?
r ggplot2 viridis
1
Note thatggplot2
has these scales build in nowadays,scale_color_viridis_c
in this case.
– Axeman
Nov 14 '18 at 5:03
2
FYI, no need to usedf_2$
insideggplot
call. You can just use bare column names
– Tung
Nov 14 '18 at 5:04
add a comment |
Here is the code:
pic = ggplot(df_2,
aes(x = df_2$X, xend = df_2$X + df_2$dx, y = df_2$Y, yend = df_2$Y + df_2$dy, color = df_2$speedkt)) +
labs(title ="Surface Currents", x = "Longitude", y = "Latitude", colour="Speed (kts)") +
geom_segment(alpha = 0.7, arrow = arrow(length = unit(0.1,"cm"))) + coord_fixed() +
theme(panel.background = element_rect(fill = "transparent",colour = NA), plot.background = element_rect(fill = "transparent",colour = NA)) +
viridis::scale_color_viridis(option = "B", direction = -1)
You can see the color gradient follows the value of df_2$speedkt
. The maximum value of df_2$speedkt
is around 2.6.
So, the maximum value of the colormap in the legend is around 2.8.
But I wish to change the maximum value of the colormap to 4.0.
What I can do?
r ggplot2 viridis
Here is the code:
pic = ggplot(df_2,
aes(x = df_2$X, xend = df_2$X + df_2$dx, y = df_2$Y, yend = df_2$Y + df_2$dy, color = df_2$speedkt)) +
labs(title ="Surface Currents", x = "Longitude", y = "Latitude", colour="Speed (kts)") +
geom_segment(alpha = 0.7, arrow = arrow(length = unit(0.1,"cm"))) + coord_fixed() +
theme(panel.background = element_rect(fill = "transparent",colour = NA), plot.background = element_rect(fill = "transparent",colour = NA)) +
viridis::scale_color_viridis(option = "B", direction = -1)
You can see the color gradient follows the value of df_2$speedkt
. The maximum value of df_2$speedkt
is around 2.6.
So, the maximum value of the colormap in the legend is around 2.8.
But I wish to change the maximum value of the colormap to 4.0.
What I can do?
r ggplot2 viridis
r ggplot2 viridis
edited Nov 14 '18 at 7:15
zx8754
29.6k76398
29.6k76398
asked Nov 14 '18 at 4:57
Justin Justin
666
666
1
Note thatggplot2
has these scales build in nowadays,scale_color_viridis_c
in this case.
– Axeman
Nov 14 '18 at 5:03
2
FYI, no need to usedf_2$
insideggplot
call. You can just use bare column names
– Tung
Nov 14 '18 at 5:04
add a comment |
1
Note thatggplot2
has these scales build in nowadays,scale_color_viridis_c
in this case.
– Axeman
Nov 14 '18 at 5:03
2
FYI, no need to usedf_2$
insideggplot
call. You can just use bare column names
– Tung
Nov 14 '18 at 5:04
1
1
Note that
ggplot2
has these scales build in nowadays, scale_color_viridis_c
in this case.– Axeman
Nov 14 '18 at 5:03
Note that
ggplot2
has these scales build in nowadays, scale_color_viridis_c
in this case.– Axeman
Nov 14 '18 at 5:03
2
2
FYI, no need to use
df_2$
inside ggplot
call. You can just use bare column names– Tung
Nov 14 '18 at 5:04
FYI, no need to use
df_2$
inside ggplot
call. You can just use bare column names– Tung
Nov 14 '18 at 5:04
add a comment |
1 Answer
1
active
oldest
votes
To answer your main question, you should be able to pass limits = c(0, 4)
as an argument to viridis::scale_color_viridis()
, i.e.
viridis::scale_color_viridis(option = "B", direction = -1, limits = c(0, 4))
A couple of other points:
- Newer versions of
ggplot2
have viridis scales built in, so you should be able to use:
scale_color_viridis_c(option = "B", direction = -1, limits = c(0, 4))
- In general, it's better not to use
df$col
inaes()
, just use the column name, e.g.
ggplot(df_2, aes(x = X, xend = X + dx, y = Y))
ggplot will look up the column names within the dataframe.
can u insert the output ?
– sai saran
Nov 14 '18 at 5:26
2
@saisaran: The question doesn't provide an easy way to reproduce the data/plot, so I can't show how it changes the plot.
– Marius
Nov 14 '18 at 5:30
add a comment |
Your Answer
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%2f53293412%2fset-the-max-value-in-colormap-when-using-scale-color-viridis%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
To answer your main question, you should be able to pass limits = c(0, 4)
as an argument to viridis::scale_color_viridis()
, i.e.
viridis::scale_color_viridis(option = "B", direction = -1, limits = c(0, 4))
A couple of other points:
- Newer versions of
ggplot2
have viridis scales built in, so you should be able to use:
scale_color_viridis_c(option = "B", direction = -1, limits = c(0, 4))
- In general, it's better not to use
df$col
inaes()
, just use the column name, e.g.
ggplot(df_2, aes(x = X, xend = X + dx, y = Y))
ggplot will look up the column names within the dataframe.
can u insert the output ?
– sai saran
Nov 14 '18 at 5:26
2
@saisaran: The question doesn't provide an easy way to reproduce the data/plot, so I can't show how it changes the plot.
– Marius
Nov 14 '18 at 5:30
add a comment |
To answer your main question, you should be able to pass limits = c(0, 4)
as an argument to viridis::scale_color_viridis()
, i.e.
viridis::scale_color_viridis(option = "B", direction = -1, limits = c(0, 4))
A couple of other points:
- Newer versions of
ggplot2
have viridis scales built in, so you should be able to use:
scale_color_viridis_c(option = "B", direction = -1, limits = c(0, 4))
- In general, it's better not to use
df$col
inaes()
, just use the column name, e.g.
ggplot(df_2, aes(x = X, xend = X + dx, y = Y))
ggplot will look up the column names within the dataframe.
can u insert the output ?
– sai saran
Nov 14 '18 at 5:26
2
@saisaran: The question doesn't provide an easy way to reproduce the data/plot, so I can't show how it changes the plot.
– Marius
Nov 14 '18 at 5:30
add a comment |
To answer your main question, you should be able to pass limits = c(0, 4)
as an argument to viridis::scale_color_viridis()
, i.e.
viridis::scale_color_viridis(option = "B", direction = -1, limits = c(0, 4))
A couple of other points:
- Newer versions of
ggplot2
have viridis scales built in, so you should be able to use:
scale_color_viridis_c(option = "B", direction = -1, limits = c(0, 4))
- In general, it's better not to use
df$col
inaes()
, just use the column name, e.g.
ggplot(df_2, aes(x = X, xend = X + dx, y = Y))
ggplot will look up the column names within the dataframe.
To answer your main question, you should be able to pass limits = c(0, 4)
as an argument to viridis::scale_color_viridis()
, i.e.
viridis::scale_color_viridis(option = "B", direction = -1, limits = c(0, 4))
A couple of other points:
- Newer versions of
ggplot2
have viridis scales built in, so you should be able to use:
scale_color_viridis_c(option = "B", direction = -1, limits = c(0, 4))
- In general, it's better not to use
df$col
inaes()
, just use the column name, e.g.
ggplot(df_2, aes(x = X, xend = X + dx, y = Y))
ggplot will look up the column names within the dataframe.
answered Nov 14 '18 at 5:02
MariusMarius
31.6k97174
31.6k97174
can u insert the output ?
– sai saran
Nov 14 '18 at 5:26
2
@saisaran: The question doesn't provide an easy way to reproduce the data/plot, so I can't show how it changes the plot.
– Marius
Nov 14 '18 at 5:30
add a comment |
can u insert the output ?
– sai saran
Nov 14 '18 at 5:26
2
@saisaran: The question doesn't provide an easy way to reproduce the data/plot, so I can't show how it changes the plot.
– Marius
Nov 14 '18 at 5:30
can u insert the output ?
– sai saran
Nov 14 '18 at 5:26
can u insert the output ?
– sai saran
Nov 14 '18 at 5:26
2
2
@saisaran: The question doesn't provide an easy way to reproduce the data/plot, so I can't show how it changes the plot.
– Marius
Nov 14 '18 at 5:30
@saisaran: The question doesn't provide an easy way to reproduce the data/plot, so I can't show how it changes the plot.
– Marius
Nov 14 '18 at 5:30
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%2f53293412%2fset-the-max-value-in-colormap-when-using-scale-color-viridis%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
Note that
ggplot2
has these scales build in nowadays,scale_color_viridis_c
in this case.– Axeman
Nov 14 '18 at 5:03
2
FYI, no need to use
df_2$
insideggplot
call. You can just use bare column names– Tung
Nov 14 '18 at 5:04