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?
To answer your main question, you should be able to pass
limits = c(0, 4)
as an argument toviridis::scale_color_viridis()
, i.e.A couple of other points:
ggplot2
have viridis scales built in, so you should be able to use:df$col
inaes()
, just use the column name, e.g.ggplot will look up the column names within the dataframe.