Reputation: 27
I have the following data in R - a column showing the names of cities and a column showing growth of incomes. I would like to create a heat map using this data. How could i do this? Is it even possible to create heat maps for one column of data
say data is something like:
City Data
New York 780
LA 982
DC 111
Boston 893
Chicago 989
And continues on many rows. Thanks for your help!
Upvotes: 2
Views: 1684
Reputation: 4283
It may make sense to have a heatmap for one column, if you want to visualize how close or how far away e.g. cities are regarding that 1 item measured.
# your data
df <- data.frame(
City = c("New York", "LA", "DC", "Boston", "Chicago"),
Data = c(780, 982, 111, 893, 989)
)
# calculate distance/dissimilarity matrix (a dist object)
distance <- dist(df$Data, diag = TRUE, upper = TRUE)
# transform to matrix and set the labels
distanceM <- as.matrix(distance)
rownames(distanceM) <- df$City
colnames(distanceM) <- df$City
# create heatmap
heatmap(distanceM)
# or without reordering and without dendrograms
heatmap(distanceM, Colv = NA, Rowv = NA)
type ?heatmap
for more details
Please let me know whether this is what you want.
Upvotes: 1