2015-11-19 174 views
1

我有如下表:的R-Studio Mosaicplot和條件格式

Server Package  Version  Status 
1 Serv1 Pack1   Ver1 Up To Date 
2 Serv1 Pack2   Ver1  Outdated 
3 Serv2 Pack1 Not Installed Not Installed 
4 Serv2 Pack2   Ver2 Up To Date 
5 Serv3 Pack1   Ver1 Up To Date 
6 Serv3 Pack2 Not Installed Not Installed 

我想創建一個馬賽克圖形顯示服務器與包裝,用彩色來表示自己的狀態所產生的地磚。

我使用:

mosaicplot(mini_conda$Server~mini_conda$Package, 
xlab = "Server", 
ylab = "Package", 
main = "") 

產生的情節幾乎是正確的,但我無法弄清楚如何正確顏色的瓷磚。

感謝,

更新:在dput 數據()做

> (dput(mini_conda)) 
structure(list(Server = structure(c(1L, 1L, 2L, 2L, 3L, 3L), .Label = c("Serv1", 
"Serv2", "Serv3"), class = "factor"), Package = structure(c(1L, 
2L, 1L, 2L, 1L, 2L), .Label = c("Pack1", "Pack2"), class = "factor"), 
    Version = structure(c(2L, 2L, 1L, 3L, 2L, 1L), .Label = c("Not Installed", 
    "Ver1", "Ver2"), class = "factor"), Status = structure(c(3L, 
    2L, 1L, 3L, 3L, 1L), .Label = c("Not Installed", "Outdated", 
    "Up To Date"), class = "factor")), .Names = c("Server", "Package", 
"Version", "Status"), class = "data.frame", row.names = c(NA, 
-6L)) 
    Server Package  Version  Status 
1 Serv1 Pack1   Ver1 Up To Date 
2 Serv1 Pack2   Ver1  Outdated 
3 Serv2 Pack1 Not Installed Not Installed 
4 Serv2 Pack2   Ver2 Up To Date 
5 Serv3 Pack1   Ver1 Up To Date 
6 Serv3 Pack2 Not Installed Not Installed 
+0

你可以提供你dput格式的數據? (dput(mini_conda))? – Heroka

+0

查看原始問題的更新。 – SML

回答

0

的一種方式,這是與vcd包:

# install.packages("vcd") 
library(vcd) 
mosaic(~ Server + Package + Status, data = mini_conda, 
     highlighting = "Status", direction = c("v", "h", "h"), 
     highlighting_fill = c("lightblue", "pink", "lightgreen")) 

mosaic

根據數據,你可能想使用ggplot2

# install.packages("ggplot2") 
library(ggplot2) 
ggplot(mini_conda, aes(x = Server, y = Package, fill = Status)) + 
    geom_tile() 

ggplot

0

一個ggplot方法:

p1 <- ggplot(mini_conda, aes(x = "", y = Package)) + 
    geom_tile(aes(fill=Status)) + 
    facet_grid(.~Server) + 
    coord_fixed() + 
    scale_fill_manual(values = c("Not Installed"="red", 
         "Outdated"="orange", 
         "Up To Date" = "green")) + 
    theme_bw() + 
    theme(
    axis.ticks.x=element_blank(), 
    strip.background = element_blank() 
) + labs(
    x="", y="" 
) 

enter image description here