Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R geom_瓷砖和鳞片颜色蒸馏器的问题_R_Ggplot2_Colors - Fatal编程技术网

R geom_瓷砖和鳞片颜色蒸馏器的问题

R geom_瓷砖和鳞片颜色蒸馏器的问题,r,ggplot2,colors,R,Ggplot2,Colors,我想使用geom\u tile()创建一个相关图。这是一段可复制的代码: library(ggplot2) df.m <- structure(list(Trait = structure(c(6L, 5L, 1L, 3L, 2L, 9L, 4L, 10L, 11L, 7L, 8L, 6L, 5L, 1L, 3L, 2L, 9L, 4L, 10L, 11L, 7L, 8L, 6L, 5L, 1L, 3L, 2L, 9L, 4L, 10L, 11L, 7L, 8L), .Label =

我想使用
geom\u tile()
创建一个相关图。这是一段可复制的代码:

library(ggplot2)

df.m <- structure(list(Trait = structure(c(6L, 5L, 1L, 3L, 2L, 9L, 4L, 
10L, 11L, 7L, 8L, 6L, 5L, 1L, 3L, 2L, 9L, 4L, 10L, 11L, 7L, 8L, 
6L, 5L, 1L, 3L, 2L, 9L, 4L, 10L, 11L, 7L, 8L), .Label = c("R1", 
"R2", "R3", "R4", "R5", 
"R6", "R7", "R8", 
"R9", "R10", 
"R11"), class = "factor"), Variable = structure(c(3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L
), .Label = c("C1", "C2", "C3"), class = "factor"), 
    value = c(0.967444360256195, 0.937379062175751, 0.647411823272705, 
    0.512605130672455, 0.50750744342804, 0.508640229701996, 0.508640229701996, 
    0.503542542457581, 0.442936152219772, 0.510905921459198, 
    0.504675328731537, NA, 0.834005177021027, 0.667642116546631, 
    0.579914391040802, 0.579344689846039, 0.536050498485565, 
    0.532062888145447, 0.52408766746521, 0.520099997520447, 0.504719197750092, 
    0.450031787157059, NA, NA, 0.571457028388977, 0.451690584421158, 
    0.354736804962158, 0.46138596534729, 0.477354824542999, 0.447128057479858, 
    0.287439465522766, 0.498456537723541, 0.508722245693207)), .Names = c("Trait", 
"Variable", "value"), row.names = c(NA, -33L), class = "data.frame")

p <- ggplot(na.omit(df.m)) + aes(x = Variable, y = Trait, fill = value) +        
        geom_tile(colour = "white", size = 0.75) +     
            scale_colour_distiller(limits = c(-1, 1), direction = -1, palette = "RdBu", name = "Coefficient") +
            scale_size(range = c(0,20), name = title, guide = "none") +
        geom_text(data = df.m, aes(x = Variable, y = Trait, label = sprintf("%.2f", value)), size = 4, inherit.aes = FALSE) +

        theme(plot.title = element_text(size = 20), axis.text.y = element_text(size = 10), 
                axis.text.x = element_text(size = 10, angle = 90,   hjust = 1, vjust = 0.5), 
                legend.position = "bottom", legend.margin = unit(1.0, "cm"), 
                legend.text = element_text(size = 8), legend.title = element_text(size = 10), 
                legend.key.size = unit(1.0, "cm"),
          panel.background = element_rect(fill = "white")) +

        xlab("\nVariables 1") + ylab("Variables 2\n")

plot(p)
库(ggplot2)

df.m您需要使用
缩放填充蒸馏器
,因为您将
映射到
填充
美学,而不是
颜色
美学