Reputation: 139
I need a heatmap with:
library(ggplot2)
df = data.frame(City= c(Boston, Caracas, Madrid, Tokio),
Val = c(Yes, No, No, Yes),
Sport = c("Soccer","Soccer","Soccer","Soccer"))
Upvotes: 0
Views: 772
Reputation: 174556
Your example only has a single sport, so it doesn't make a great heatmap. Here's an expanded example to give a better impression of the aesthetic:
library(ggplot2)
set.seed(69)
df <- data.frame(City= rep(c("Boston", "Caracas", "Madrid", "Tokio"), 4),
Val = sample(c("Yes", "No"), 16, TRUE),
Sport = rep(c("Soccer","Hockey", "Tennis", "Darts"), each = 4))
ggplot(df, aes(City, Sport, fill = Val)) +
geom_tile(color = "#00000022") +
scale_fill_manual(values = c("red", "forestgreen")) +
coord_equal() +
theme_bw() +
labs(fill = "Sport popular?")
Created on 2020-10-23 by the reprex package (v0.3.0)
Upvotes: 1