Etienne B. Racine
2013-06-20 18:39:25 UTC
Hi list,
I'd like to generate an circular continuous color/fill scale to indicate
direction (angular data). For instance the gradient would be, North, blue;
East, white; South, red; West dark purple (and would loop to blue). That
would create a North-south gradient in the blue-red and a light-dark
gradient along the East-West axis. The problem with actual gradients is
that either colors aren't looping (sharp break between first and last
color) or colors are repeated (first and last colors are the same in order
for the gradient to loop). That's what happen when I use
scale_fill_gradientn(). So my question is two folds how to generate a
scale_fill_circular and then add a circular scale to a plot.
Here's a visual explanation :
circular_scale <- function(from = 0, to = 2 * pi, steps = 8, by = to /
steps, offset = -pi * by / to, vertical = 3, colours = c("#0088FF",
"#ffffff", "#F51D1D", "#400038", "#0088FF"), text_colour = "#aaaaaaaa") {
pp = data.frame(x = seq(from, to, by = by), y = vertical - 1)
ggplot(pp, aes(x=x, y=y)) +
geom_tile(aes(fill = x)) +
geom_text(aes(label = round(x, 1)), colour = text_colour) +
list(scale_y_continuous(limits = c(0, vertical)),
scale_x_continuous(breaks = seq(from, to, by = by)),
coord_polar(start = offset) ,
scale_fill_gradientn(colours = colours, limits = c(from, to)),
}
circular_scale(0, 360)
# As I increase the steps, the problem is less and less obvious :
circular_scale(steps = 40)
This is a mock-up of the result I'd like to achieve (pixel orientation of
the volcano dataset).
<Loading Image...>
Any help would be appreciated; suggestions of prettier colors would also be
welcome.
Etienne
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
To post: email ggplot2-/***@public.gmane.org
To unsubscribe: email ggplot2+unsubscribe-/***@public.gmane.org
More options: http://groups.google.com/group/ggplot2
---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
I'd like to generate an circular continuous color/fill scale to indicate
direction (angular data). For instance the gradient would be, North, blue;
East, white; South, red; West dark purple (and would loop to blue). That
would create a North-south gradient in the blue-red and a light-dark
gradient along the East-West axis. The problem with actual gradients is
that either colors aren't looping (sharp break between first and last
color) or colors are repeated (first and last colors are the same in order
for the gradient to loop). That's what happen when I use
scale_fill_gradientn(). So my question is two folds how to generate a
scale_fill_circular and then add a circular scale to a plot.
Here's a visual explanation :
circular_scale <- function(from = 0, to = 2 * pi, steps = 8, by = to /
steps, offset = -pi * by / to, vertical = 3, colours = c("#0088FF",
"#ffffff", "#F51D1D", "#400038", "#0088FF"), text_colour = "#aaaaaaaa") {
pp = data.frame(x = seq(from, to, by = by), y = vertical - 1)
ggplot(pp, aes(x=x, y=y)) +
geom_tile(aes(fill = x)) +
geom_text(aes(label = round(x, 1)), colour = text_colour) +
list(scale_y_continuous(limits = c(0, vertical)),
scale_x_continuous(breaks = seq(from, to, by = by)),
coord_polar(start = offset) ,
scale_fill_gradientn(colours = colours, limits = c(from, to)),
}
circular_scale(0, 360)
# As I increase the steps, the problem is less and less obvious :
circular_scale(steps = 40)
This is a mock-up of the result I'd like to achieve (pixel orientation of
the volcano dataset).
<Loading Image...>
Any help would be appreciated; suggestions of prettier colors would also be
welcome.
Etienne
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
To post: email ggplot2-/***@public.gmane.org
To unsubscribe: email ggplot2+unsubscribe-/***@public.gmane.org
More options: http://groups.google.com/group/ggplot2
---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.