我有以下隨機創建的資料:
t<- matrix(sample.int(100,size=20,replace=TRUE),nrow=12,ncol=20)
a = list()
b = list()
for (x in (1:20) ) b[[x]] <- paste0("X_", x)
for (x in (1:12) ) a[[x]] <- paste0("X", x)
row.names(t) <- rbind(a)
colnames(t) <- rbind(b)
t <- as.data.frame(t)
這t是一個假設的雙向頻率表,我正在嘗試使用 ggplot2繪制類似于
uj5u.com熱心網友回復:
這是對 Jon Springs 代碼的修改,并進行了一些“布局”調整:
library(tidyverse)
df %>%
rownames_to_column() %>%
pivot_longer(-rowname) %>%
mutate(across(rowname:name, fct_inorder)) %>%
ggplot(aes(x = 1, y = value, fill=value))
geom_col(width = 0.5)
geom_text(aes(x = 1, y = 0, label = value), vjust = 1.1, size = 2.5)
scale_x_continuous(breaks = NULL)
scale_y_continuous(breaks = NULL)
facet_grid(rowname~name, switch = "both")
coord_cartesian(clip = "off")
theme_void()
theme(strip.background = element_blank(),
strip.text.y.left = element_text(angle = 0),
panel.spacing = unit(1, "lines"),
strip.placement = "outside",
strip.switch.pad.grid = unit(0.2, "in"))
guides(fill="none")

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/319259.html
上一篇:使用ggplot為分位數添加顏色
下一篇:生成的軸刻度標簽中的斜體字母
