R-Studio马赛克打印和条件格式
我有下表:R-Studio马赛克打印和条件格式,r,plot,formatting,conditional,mosaic,R,Plot,Formatting,Conditional,Mosaic,我有下表: 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
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()中的数据
一种方法是使用
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"))
根据数据的不同,您可能需要使用ggplot2
:
# install.packages("ggplot2")
library(ggplot2)
ggplot(mini_conda, aes(x = Server, y = Package, fill = Status)) +
geom_tile()
一种方法是使用
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"))
根据数据的不同,您可能需要使用ggplot2
:
# install.packages("ggplot2")
library(ggplot2)
ggplot(mini_conda, aes(x = Server, y = Package, fill = Status)) +
geom_tile()
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=""
)
p1ggplot方法:
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=""
)
p1您能以dput格式向您提供数据吗?(dput(mini_conda))?请参阅原始问题的更新。您能否以dput格式提供数据?(dput(mini_conda))?参见原始问题的更新。