我使用 R 中的 ggplot2 创建一个点图,其中 x 轴是变量名,y 轴是细胞系 ID。该图由组变量(“焦点形成”、“软琼脂”、“3D 基质胶生长”)构成。
我想要水平旋转或翻转整个图,以便:
目前在左边的变成了右边的(反之亦然)。
方面标签(当前位于左侧)移动到右侧。
ID 标签(当前位于右侧)移至左侧。
简而言之,我想要当前图在垂直轴上的镜像,就像沿 y 轴旋转 180 度一样。
这是我正在使用的代码和数据:
library(dplyr)
library(tidyverse)
library(ggplot2)
df1 <- structure(list(ID = c("OVCAR3", "OVCR", "AFC", "OVCAR3", "OVCR", "AFC",
"OVCAR3", "OVCR", "AFC"),
V = c(1.467, 1.402, 1.445, 1.48, 1.313, 1.418, 1.5, 1.456, 1.489),
N = c(0.823, 0.762, 0.34, 0.738, 0.739, 0.533, 0.891, 0.904, 0.412),
A = c(0.734, 0.771, 1.098, 0.793, 0.799, 0.938, 1.12, 0.853, 1.076),
`N+A` = c(-1.075, -0.577, -0.832, -1.025, -0.633, -0.977, -1.21, -0.517, -1.032),
C = c(-0.239, 0.342, 0.33, -0.314, 0.341, 0.202, -0.324, 0.303, 0.207),
`N+C` = c(-1.403, -1.002, -1.162, -1.5, -1.106, -1.22, -1.329, -1.043, -1.164),
T = c(0.113, 0.487, 0.393, -0.105, 0.336, 0.366, 0.089, 0.329, 0.275),
`N+T` = c(-1.25, -1.045, -1.066, -1.206, -0.981, -0.928, -1.321, -1.12, -1.032),
Group = c("Foci formation", "Foci formation", "Foci formation",
"Soft agar", "Soft agar", "Soft agar",
"3D Matrigel growth", "3D Matrigel growth", "3D Matrigel growth")),
class = "data.frame", row.names = c(NA, -9L))
# Convert to long format
df_long <- df1 %>%
pivot_longer(cols = V:`N+T`, names_to = "Variable", values_to = "Z_score")
# Create dot plot
ggplot(df_long, aes(x = Variable, y = ID, color = Z_score, size = abs(Z_score))) +
geom_point() +
facet_grid(rows = vars(Group), scales = "free_y", space = "free_y") +
scale_color_gradient2(low = "blue", mid = "white", high = "red", midpoint = 0) +
theme_minimal() +
theme(
axis.text.x = element_text(angle = 45, hjust = 1),
strip.text.y = element_text(angle = 0)
) +
labs(x = "Variables", y = "Cell Line", color = "Z-Score", size = "Magnitude")
输出: