Raster-like timeseries graph in ggplot2












4















I'm trying to recreate a graph like the one here using ggplot2.



enter image description here



I can get pretty close if I mess around with the size and shape of points using coord_equal, but...



Example data and code

library(ggplot2)
df <- data.frame()
Years <- 1990:2020
for(i in 1:length(Years)) {
Year <- Years[i]
week <-1:52
value <- sort(round(rnorm(52, 50, 30), 0))
df.small <- data.frame(Year = Year, week = week, value = value)
df <- bind_rows(df, df.small)
}


ggplot(df, aes(week, Year, color = value)) +
geom_point(shape = 15, size = 2.7) +
scale_color_gradientn(colours = rainbow(10)) +
coord_equal()


enter image description here



The problem is,



with my real data I want to "stretch" the graph so I can see it more clearly (my timeseries is shorter) and when I don't use coord_equal, squares don't fill the graphing area:



ggplot(df, aes(week, Year, color = value)) +
geom_point(shape = 15, size = 2.7) +
scale_color_gradientn(colours = rainbow(10))


enter image description here










share|improve this question




















  • 2





    Side note: please scrap rainbow colour scales: nature.com/articles/519291d

    – Tung
    Nov 19 '18 at 18:27






  • 2





    You can find better colormaps than rainbow in this thread stackoverflow.com/q/37482977/786542

    – Tung
    Nov 19 '18 at 18:28






  • 1





    This is amazing. I use colorblind-friendly colors in all my publications... why would I do anything less on SO? Thanks for the reminder, Tung :)

    – Nova
    Nov 19 '18 at 21:16











  • that's great to hear. The world needs more thoughtful scientists like you :)

    – Tung
    Nov 19 '18 at 22:33
















4















I'm trying to recreate a graph like the one here using ggplot2.



enter image description here



I can get pretty close if I mess around with the size and shape of points using coord_equal, but...



Example data and code

library(ggplot2)
df <- data.frame()
Years <- 1990:2020
for(i in 1:length(Years)) {
Year <- Years[i]
week <-1:52
value <- sort(round(rnorm(52, 50, 30), 0))
df.small <- data.frame(Year = Year, week = week, value = value)
df <- bind_rows(df, df.small)
}


ggplot(df, aes(week, Year, color = value)) +
geom_point(shape = 15, size = 2.7) +
scale_color_gradientn(colours = rainbow(10)) +
coord_equal()


enter image description here



The problem is,



with my real data I want to "stretch" the graph so I can see it more clearly (my timeseries is shorter) and when I don't use coord_equal, squares don't fill the graphing area:



ggplot(df, aes(week, Year, color = value)) +
geom_point(shape = 15, size = 2.7) +
scale_color_gradientn(colours = rainbow(10))


enter image description here










share|improve this question




















  • 2





    Side note: please scrap rainbow colour scales: nature.com/articles/519291d

    – Tung
    Nov 19 '18 at 18:27






  • 2





    You can find better colormaps than rainbow in this thread stackoverflow.com/q/37482977/786542

    – Tung
    Nov 19 '18 at 18:28






  • 1





    This is amazing. I use colorblind-friendly colors in all my publications... why would I do anything less on SO? Thanks for the reminder, Tung :)

    – Nova
    Nov 19 '18 at 21:16











  • that's great to hear. The world needs more thoughtful scientists like you :)

    – Tung
    Nov 19 '18 at 22:33














4












4








4








I'm trying to recreate a graph like the one here using ggplot2.



enter image description here



I can get pretty close if I mess around with the size and shape of points using coord_equal, but...



Example data and code

library(ggplot2)
df <- data.frame()
Years <- 1990:2020
for(i in 1:length(Years)) {
Year <- Years[i]
week <-1:52
value <- sort(round(rnorm(52, 50, 30), 0))
df.small <- data.frame(Year = Year, week = week, value = value)
df <- bind_rows(df, df.small)
}


ggplot(df, aes(week, Year, color = value)) +
geom_point(shape = 15, size = 2.7) +
scale_color_gradientn(colours = rainbow(10)) +
coord_equal()


enter image description here



The problem is,



with my real data I want to "stretch" the graph so I can see it more clearly (my timeseries is shorter) and when I don't use coord_equal, squares don't fill the graphing area:



ggplot(df, aes(week, Year, color = value)) +
geom_point(shape = 15, size = 2.7) +
scale_color_gradientn(colours = rainbow(10))


enter image description here










share|improve this question
















I'm trying to recreate a graph like the one here using ggplot2.



enter image description here



I can get pretty close if I mess around with the size and shape of points using coord_equal, but...



Example data and code

library(ggplot2)
df <- data.frame()
Years <- 1990:2020
for(i in 1:length(Years)) {
Year <- Years[i]
week <-1:52
value <- sort(round(rnorm(52, 50, 30), 0))
df.small <- data.frame(Year = Year, week = week, value = value)
df <- bind_rows(df, df.small)
}


ggplot(df, aes(week, Year, color = value)) +
geom_point(shape = 15, size = 2.7) +
scale_color_gradientn(colours = rainbow(10)) +
coord_equal()


enter image description here



The problem is,



with my real data I want to "stretch" the graph so I can see it more clearly (my timeseries is shorter) and when I don't use coord_equal, squares don't fill the graphing area:



ggplot(df, aes(week, Year, color = value)) +
geom_point(shape = 15, size = 2.7) +
scale_color_gradientn(colours = rainbow(10))


enter image description here







r ggplot2 time-series raster






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 18:21







Nova

















asked Nov 19 '18 at 18:11









NovaNova

1,3491229




1,3491229








  • 2





    Side note: please scrap rainbow colour scales: nature.com/articles/519291d

    – Tung
    Nov 19 '18 at 18:27






  • 2





    You can find better colormaps than rainbow in this thread stackoverflow.com/q/37482977/786542

    – Tung
    Nov 19 '18 at 18:28






  • 1





    This is amazing. I use colorblind-friendly colors in all my publications... why would I do anything less on SO? Thanks for the reminder, Tung :)

    – Nova
    Nov 19 '18 at 21:16











  • that's great to hear. The world needs more thoughtful scientists like you :)

    – Tung
    Nov 19 '18 at 22:33














  • 2





    Side note: please scrap rainbow colour scales: nature.com/articles/519291d

    – Tung
    Nov 19 '18 at 18:27






  • 2





    You can find better colormaps than rainbow in this thread stackoverflow.com/q/37482977/786542

    – Tung
    Nov 19 '18 at 18:28






  • 1





    This is amazing. I use colorblind-friendly colors in all my publications... why would I do anything less on SO? Thanks for the reminder, Tung :)

    – Nova
    Nov 19 '18 at 21:16











  • that's great to hear. The world needs more thoughtful scientists like you :)

    – Tung
    Nov 19 '18 at 22:33








2




2





Side note: please scrap rainbow colour scales: nature.com/articles/519291d

– Tung
Nov 19 '18 at 18:27





Side note: please scrap rainbow colour scales: nature.com/articles/519291d

– Tung
Nov 19 '18 at 18:27




2




2





You can find better colormaps than rainbow in this thread stackoverflow.com/q/37482977/786542

– Tung
Nov 19 '18 at 18:28





You can find better colormaps than rainbow in this thread stackoverflow.com/q/37482977/786542

– Tung
Nov 19 '18 at 18:28




1




1





This is amazing. I use colorblind-friendly colors in all my publications... why would I do anything less on SO? Thanks for the reminder, Tung :)

– Nova
Nov 19 '18 at 21:16





This is amazing. I use colorblind-friendly colors in all my publications... why would I do anything less on SO? Thanks for the reminder, Tung :)

– Nova
Nov 19 '18 at 21:16













that's great to hear. The world needs more thoughtful scientists like you :)

– Tung
Nov 19 '18 at 22:33





that's great to hear. The world needs more thoughtful scientists like you :)

– Tung
Nov 19 '18 at 22:33












1 Answer
1






active

oldest

votes


















3














Is this as simple as using the geom_raster geom?



ggplot(df, aes(week, Year)) +
geom_raster(aes(fill = value)) +
scale_fill_gradientn(colours = rainbow(10)) +
coord_equal()


enter image description here






share|improve this answer
























  • Yes! I just didn't know you could use geom_raster without spatial info. This is a real "face-palm" moment, but I really appreciate the help!!

    – Nova
    Nov 19 '18 at 21:15











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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53380410%2fraster-like-timeseries-graph-in-ggplot2%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









3














Is this as simple as using the geom_raster geom?



ggplot(df, aes(week, Year)) +
geom_raster(aes(fill = value)) +
scale_fill_gradientn(colours = rainbow(10)) +
coord_equal()


enter image description here






share|improve this answer
























  • Yes! I just didn't know you could use geom_raster without spatial info. This is a real "face-palm" moment, but I really appreciate the help!!

    – Nova
    Nov 19 '18 at 21:15
















3














Is this as simple as using the geom_raster geom?



ggplot(df, aes(week, Year)) +
geom_raster(aes(fill = value)) +
scale_fill_gradientn(colours = rainbow(10)) +
coord_equal()


enter image description here






share|improve this answer
























  • Yes! I just didn't know you could use geom_raster without spatial info. This is a real "face-palm" moment, but I really appreciate the help!!

    – Nova
    Nov 19 '18 at 21:15














3












3








3







Is this as simple as using the geom_raster geom?



ggplot(df, aes(week, Year)) +
geom_raster(aes(fill = value)) +
scale_fill_gradientn(colours = rainbow(10)) +
coord_equal()


enter image description here






share|improve this answer













Is this as simple as using the geom_raster geom?



ggplot(df, aes(week, Year)) +
geom_raster(aes(fill = value)) +
scale_fill_gradientn(colours = rainbow(10)) +
coord_equal()


enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 '18 at 18:23









Rui BarradasRui Barradas

16.6k51730




16.6k51730













  • Yes! I just didn't know you could use geom_raster without spatial info. This is a real "face-palm" moment, but I really appreciate the help!!

    – Nova
    Nov 19 '18 at 21:15



















  • Yes! I just didn't know you could use geom_raster without spatial info. This is a real "face-palm" moment, but I really appreciate the help!!

    – Nova
    Nov 19 '18 at 21:15

















Yes! I just didn't know you could use geom_raster without spatial info. This is a real "face-palm" moment, but I really appreciate the help!!

– Nova
Nov 19 '18 at 21:15





Yes! I just didn't know you could use geom_raster without spatial info. This is a real "face-palm" moment, but I really appreciate the help!!

– Nova
Nov 19 '18 at 21:15


















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53380410%2fraster-like-timeseries-graph-in-ggplot2%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?