Calendar Heat Map

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Calendar Heat Map

reichmaj
r-Help Form

 

I'm working on a "Time-Series Calendar Heatmap" using the following code.

 

ggplot(myData, aes(monthweek, weekdayf, fill = myData $adjusted)) +

geom_tile(colour = "white") + facet_grid(year(myData $date)~monthf) +

scale_fill_gradient(low="red", high="green") +

xlab("Week of Month") + ylab("") +

ggtitle("Time-Series Calendar Heatmap ") + labs(fill = "Price")

 

While the ggplot commands do (almost) what I want I can't figure out how to
change my color scaling. While scale_fill_gradient(low="red", high="green")
does what I ask, that is create a color gradient from red to green it not
what I thought it would be. What I need is discreet colors something like 0
- grey; 1:5 - blue; 6:10 - green etc.  How to I set discrete colors for
groups of values. A color ramp would work but I need to separately color
those cells with 0 counts.

 

Jeff Reichman


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Calendar Heat Map

Jeff Newmiller
ggplot automatically chooses continuous or discrete scales depending on the type of column you give it... so don't give it a numeric column (integers are a subset of numeric)... give it a character (lazy) or factor (better for controlling what the output looks like) value for your colour specification.

Read

?cut

for one clean way to make a new factor column in your data set before you give it to ggplot. Note that if you don't like the labels it generates automatically you can specify them yourself.

On February 5, 2019 2:28:28 PM PST, [hidden email] wrote:

>r-Help Form
>
>
>
>I'm working on a "Time-Series Calendar Heatmap" using the following
>code.
>
>
>
>ggplot(myData, aes(monthweek, weekdayf, fill = myData $adjusted)) +
>
>geom_tile(colour = "white") + facet_grid(year(myData $date)~monthf) +
>
>scale_fill_gradient(low="red", high="green") +
>
>xlab("Week of Month") + ylab("") +
>
>ggtitle("Time-Series Calendar Heatmap ") + labs(fill = "Price")
>
>
>
>While the ggplot commands do (almost) what I want I can't figure out
>how to
>change my color scaling. While scale_fill_gradient(low="red",
>high="green")
>does what I ask, that is create a color gradient from red to green it
>not
>what I thought it would be. What I need is discreet colors something
>like 0
>- grey; 1:5 - blue; 6:10 - green etc.  How to I set discrete colors for
>groups of values. A color ramp would work but I need to separately
>color
>those cells with 0 counts.
>
>
>
>Jeff Reichman
>
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>[hidden email] mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

--
Sent from my phone. Please excuse my brevity.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Calendar Heat Map

reichmaj
Jeff

Thanks - that’s easy enough

Jeff

-----Original Message-----
From: Jeff Newmiller <[hidden email]>
Sent: Wednesday, February 6, 2019 7:09 AM
To: [hidden email]; [hidden email]
Subject: Re: [R] Calendar Heat Map

ggplot automatically chooses continuous or discrete scales depending on the type of column you give it... so don't give it a numeric column (integers are a subset of numeric)... give it a character (lazy) or factor (better for controlling what the output looks like) value for your colour specification.

Read

?cut

for one clean way to make a new factor column in your data set before you give it to ggplot. Note that if you don't like the labels it generates automatically you can specify them yourself.

On February 5, 2019 2:28:28 PM PST, [hidden email] wrote:

>r-Help Form
>
>
>
>I'm working on a "Time-Series Calendar Heatmap" using the following
>code.
>
>
>
>ggplot(myData, aes(monthweek, weekdayf, fill = myData $adjusted)) +
>
>geom_tile(colour = "white") + facet_grid(year(myData $date)~monthf) +
>
>scale_fill_gradient(low="red", high="green") +
>
>xlab("Week of Month") + ylab("") +
>
>ggtitle("Time-Series Calendar Heatmap ") + labs(fill = "Price")
>
>
>
>While the ggplot commands do (almost) what I want I can't figure out
>how to change my color scaling. While scale_fill_gradient(low="red",
>high="green")
>does what I ask, that is create a color gradient from red to green it
>not what I thought it would be. What I need is discreet colors
>something like 0
>- grey; 1:5 - blue; 6:10 - green etc.  How to I set discrete colors for
>groups of values. A color ramp would work but I need to separately
>color those cells with 0 counts.
>
>
>
>Jeff Reichman
>
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>[hidden email] mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

--
Sent from my phone. Please excuse my brevity.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.