我有以下代码创建轮廓图:
library(ggplot2)
library(tidyverse)
vector1 <- c(0,1,4,9,11,18)
vector2 <- c(1,5,7,9,14,16,17,20,40)
theme_bw()
result <- matrix(0, nrow = length(vector1), ncol = length(vector2))
for (i in seq_len(length(vector1))) {
for (j in seq_len(length(vector2))) {
result[i,j] <- 1 + (vector2[j] * (vector1[i]))
}
}
rownames(result) <- vector1
colnames(result) <- vector2
as.data.frame(result) %>%
rownames_to_column() %>%
gather(key, value, -rowname) %>%
mutate(key = as.numeric(key),
rowname = as.numeric(rowname)) %>%
ggplot() +
geom_contour(aes(x = rowname, y = key, z = value))
但是我想要这样的东西:
如何填充R
中的等高线图,以得到像彩色示例一样的图?