I created a simple data frame of sales and price for a fictitious
product to use in a larger example for a client. This made-up product
has a promotion flyer which is just a binary 0/1 variable (1 = flyer
promotion, 0 = no flyer promotion). The following code creates a
scatter to show the relationship between sales and price with the flyer
promotion indicate:
p <- ggplot(data = x, aes(x = own.price, y = sales, colour = flyer))
p <- p + geom_point(size = 2)
p <- p + scale_colour_hue("Flyer\nPromotion")
p <- p + scale_x_continuous("Price per Unit ($)", labels = dollar) +
scale_y_continuous("Unit Sales (000)")
p <- p + opts(title = "Beverage Product Study\nPrice and Sales Data\nRaw
Data\nFlyer Promotion Effect")
p
My question is: how can I control the color of the dots? I want one to
be black and the other red. I'm using the latest version of ggplot2.
Thanks,
Walt
________________________
Walter R. Paczkowski, Ph.D.
Data Analytics Corp.
44 Hamilton Lane
Plainsboro, NJ 08536
________________________
(V) 609-936-8999
(F) 609-936-3733
wa...@dataanalyticscorp.com
www.dataanalyticscorp.com
_____________________________________________________
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+unsubscribe@googlegroups.com
More options: http://groups.google.com/group/ggplot2
scale_colour_manual(values=c("red", "black"))
Jean-Olivier Irisson
---
Observatoire Océanologique
Station Zoologique, B.P. 28, Chemin du Lazaret
06230 Villefranche-sur-Mer
Tel: +33 04 93 76 38 04
Mob: +33 06 21 05 19 90
http://jo.irisson.com/
p <- p + facet_grid(. ~ flyer)
to get two panels: one for data with a flyer promotion, the other
without a flyer promotion. How do I get one panel to have red dots and
the other black dots?
Thanks,
Walt
On 3/29/2012 9:31 AM, Jean-Olivier Irisson wrote:
> On 2012-Mar-29, at 15:28 , Data Analytics Corp. wrote:
>> My question is: how can I control the color of the dots? I want one to be black and the other red. I'm using the latest version of ggplot2.
> scale_colour_manual(values=c("red", "black"))
>
> Jean-Olivier Irisson
> ---
> Observatoire Oc�anologique
It's not clear whether your binary variable is factor, character or
numeric, and it matters in terms of the specification given below.
Assuming it's numeric,
scale_color_manual('Flyer\nPromotion', values = c(0 = 'black', 1 = 'red'),
labels = c('No flyer', 'Flyer'))
If the variable is a factor, then you need something like
scale_color_manual('Flyer\,Promotion', breaks = levels(x$flyer),
values = c('black', 'red'),
labels = c('No flyer', 'Flyer'))
If it's character, then quote the 0 and 1 in the first statement.
Dennis
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2