[英]Improved Mosaic Plot (like Heatmap or bubbles)
首先將數據重新整形為長格式:
library(reshape2)
x <- melt(df)
names(x) <- c("iplan","vplan","value")
之后,您可以使用例如geom_point
輕松制作繪圖:
library(ggplot2)
ggplot(x, aes(iplan, vplan)) +
geom_point(aes(size = value), alpha=0.8, color="darkgreen", show_guide=FALSE) +
geom_text(aes(label = value), color="white") +
scale_size(range = c(15,50)) +
theme_bw()
這給了:
作為替代方案,您還可以考慮使用geom_tile
:
ggplot(x, aes(iplan, vplan)) +
geom_tile(aes(fill = value)) +
geom_text(aes(label = value), color="white") +
scale_x_discrete(expand = c(0,0)) +
scale_y_discrete(expand = c(0,0)) +
scale_fill_gradient("Legend label", low = "lightblue", high = "blue") +
theme_bw()
給出:
使用數據:
df <- structure(list(iplan = structure(1:2, .Label = c("No", "Yes"), class = "factor"), No = c(27L, 243L), Yes = c(239L, 2159L)), .Names = c("iplan", "No", "Yes"), class = "data.frame", row.names = c(NA, -2L))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.