I have two formats of my Mortality Data, one in the list form you get it from The Human Mortality Database, with Male, Female and Combined data all in columns. The other format is separated into Male and Female matrices, with just Age, year and the mortality rate in each matrix.
The first format is along the lines of
Year Age Female Male Total
1961 99 0.3 0.4 0.3
1961 98 0.4 0.5 0.4
etc.
The second format I separated to get data in the form of:
Age 1961 1962 1963 .....
0 0.02 0.02 0.02 ...
1 0.002 0.002 0.002....
etc.
I would like to be able to plot a heatmap so I can look at the cohort effects etc.
I have tried various methods found by searching online but these aren't working for the way my data is presented. The heatmaps I've produced come out completely red. Can anyone help?
I've tried this:
rnames <- France[,1] #assign labels in column 1 to "rnames"
mat_data <- data.matrix(France[,2:ncol(France)])
rownames(mat_data) <- rnames #assign row names
col_breaks = c(seq(-1,0,length=100), # for red
seq(0,0.8,length=100), # for yellow
seq(0.8,1,length=100)) # for green
my_palette <- colorRampPalette(c("red", "yellow", "green"))(n = 299)
png("location", # create PNG for the heat map
width = 5*300, # 5 x 300 pixels
height = 5*300,
res = 300, # 300 pixels per inch
pointsize = 8) # smaller font size
heatmap.2(mat_data,
cellnote=mat_data,
main="Correlation",
notecol="black",
trace="none",
margins =c(12,9),
col=my_palette,
breaks=col_breaks,
dendrogram="row",
Colv="NA")
dev.off()
Which creates a solid red heatmap, with the year listed along the bottom, and then the word Age next to the years, and then the actual ages listed along the y-axis. It also gives me an error code:
Error in seq.default(min.raw, max.raw, by = min(diff(breaks)/4)) :
invalid (to - from)/by in seq(.)
Does anyone know of a better way of producing the heatmap or what I've done wrong here?