Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
89 views
in Technique[技术] by (71.8m points)

r - Heatmaps with frequency values as color var

I need help with heatmaps, I am first timer and I usually have problems when coming to frequencies graphs.

I need to create a heatmap with date on x axis, and crepus on y axis. That is fine.

The variable I want for the color is the frequency of all species (speciesname), which would be the total sum of all species of the variable nmb_individuals, obviously by date and crepus value.

When trying it, I get a completely blank heatmap, though the scale looks good:

our_data %>% 
    ggplot(aes(date,crepus,fill=nmb_individuals)) + geom_tile()

Find a small portion of my dataset here:

      our_data <- structure(list(speciesname = c("Wood Lark", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "bunting sp.", 
"Robin", "Blackbird", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Chaffinch", "Chaffinch", 
"Chaffinch", "Chaffinch", "Cirl Bunting", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Redwing", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Chaffinch", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Blackbird", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Redwing", "Redwing", "Redwing", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Raven", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Skylark", "Blackbird", "Blackbird", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Chaffinch", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Blackbird", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Blackbird", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Redwing", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Redwing", "Redwing", "Chaffinch", "Song Thrush", 
"Dunnock", "Dunnock", "Dunnock", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Dunnock", "Song Thrush", 
"Song Thrush", "Song Thrush", "Chaffinch", "Blackbird", "Song Thrush", 
"Redwing", "Song Thrush", "Song Thrush", "Song Thrush", "Skylark", 
"Skylark", "Song Thrush", "Song Thrush", "Song Thrush", "Redwing", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Chaffinch", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Redwing", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Blackbird", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Redwing", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Blackbird", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Dunnock", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Redwing", "Song Thrush", "Song Thrush", 
"Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", "Song Thrush", 
"Song Thrush", "Redwing"), date = structure(c(18556, 18556, 18556, 
18556, 18557, 18557, 18557, 18557, 18558, 18558, 18558, 18558, 
18558, 18558, 18558, 18558, 18558, 18558, 18558, 18558, 18558, 
18559, 18559, 18559, 18559, 18559, 18559, 18559, 18559, 18559, 
18559, 18559, 18559, 18559, 18559, 18559, 18559, 18559, 18559, 
18559, 18559, 18559, 18559, 18559, 18559, 18559, 18559, 18559, 
18559, 18559, 18559, 18559, 18559, 18559, 18559, 18559, 18559, 
18559, 18559, 18559, 18559, 18559, 18559, 18559, 18559, 18559, 
18559, 18559, 18559, 18559, 18559, 18559, 18559, 18560, 18560, 
18560, 18560, 18560, 18560, 18560, 18560, 18560, 18560, 18560, 
18560, 18560, 18560, 18560, 18562, 18562, 18562, 18562, 18562, 
18562, 18562, 18563, 18563, 18563, 18563, 18563, 18563, 18563, 
18563, 18563, 18563, 18563, 18563, 18563, 18563, 18563, 18563, 
18563, 18564, 18564, 18564, 18564, 18564, 18564, 18564, 18564, 
18564, 18564, 18564, 18564, 18564, 18564, 18564, 18559, 18559, 
18559, 18559, 18559, 18559, 18558, 18558, 18558, 18558, 18558, 
18558, 18558, 18558, 18558, 18558, 18558, 18558, 18560, 18560, 
18560, 18560, 18560, 18560, 18560, 18560, 18561, 18561, 18561, 
18561, 18561, 18561, 18561, 18561, 18561, 18561, 18561, 18561, 
18561, 18561, 18561, 18562, 18562, 18562, 18562, 18562, 18562, 
18562, 18562, 18562, 18562, 18562, 18562, 18562, 18562, 18562, 
18562, 18562, 18563, 18563, 18564, 18564, 18564, 18564, 18564, 
18564, 18564, 18564, 18564, 18564, 18564, 18564, 18564, 18564, 
18564, 18564, 18564, 18564, 18564, 18564, 18556, 18558, 18558, 
18558, 18558, 18558, 18558, 18558, 18558, 18559, 18559, 18559, 
18559, 18559, 18562, 18562, 18562, 18563, 18563, 18563, 18564, 
18564, 18564, 18564, 18564, 18557, 18558, 18558, 18558, 18558, 
18558, 18558, 18558, 18559, 18559, 18559, 18559, 18559, 18560, 
18560, 18560, 18560, 18561, 18561, 18561, 18561, 18562, 18562, 
18562, 18562, 18562, 18563, 18563, 18563, 18563, 18563, 18563, 
18563, 18563, 18564, 18564, 18564, 18556, 18556, 18556, 18556, 
18557, 18558, 18558, 18558, 18558, 18558, 18558, 18559, 18559, 
18559, 18559, 18559, 18559, 18559, 18559, 18559, 18559, 18559, 
18559, 18559, 18559, 18559, 18559, 18559, 18560, 18560, 18560, 
18560, 18560, 18560, 18560, 18560, 18560, 18561, 18561, 18561, 
18561, 18561, 18561, 18561, 18561, 18561, 18561, 18561, 18561, 
18561, 18561, 18561, 18562, 18562, 18562, 18562, 18562, 18562, 
18563, 18563, 18563, 18563, 18563, 18563, 18563, 18563, 18563, 
18564, 18564, 18564, 18564, 18564, 18564, 18564

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

maybe this kind:

our_data %>% 
  ggplot(aes(date,crepus)) +
  geom_tile(aes(fill= factor(nmb_individuals)), height = 0.1)

or without factor:

our_data %>% 
  ggplot(aes(date,crepus)) +
  geom_tile(aes(fill= nmb_individuals), height = 0.1)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...