ggplot - 仅绘制颜色条
ggplot - plot only the colourbar
我希望只绘制颜色条,如果可能的话,在 window 的中心,像这样:
一个无法删除点、轴和背景的示例。
library("ggplot2")
library("viridis")
df <- data.frame(x = c(1,2,3,4,5,6), y = c(7,4,9,2,6,7))
ggplot(data = df, aes(x = x, y = y, colour = y)) +
geom_point() +
scale_color_viridis()
包 ggpubr
具有满足此需求的功能。
df <- data.frame(x = c(1,2,3,4,5,6), y = c(7,4,9,2,6,7))
p <- ggplot(data = df, aes(x = x, y = y, colour = y)) +
geom_point() +
scale_color_viridis() +
theme_minimal()
# ggpubr does this for you
library(ggpubr)
leg <- get_legend(p)
as_ggplot(leg)
我希望只绘制颜色条,如果可能的话,在 window 的中心,像这样:
一个无法删除点、轴和背景的示例。
library("ggplot2")
library("viridis")
df <- data.frame(x = c(1,2,3,4,5,6), y = c(7,4,9,2,6,7))
ggplot(data = df, aes(x = x, y = y, colour = y)) +
geom_point() +
scale_color_viridis()
包 ggpubr
具有满足此需求的功能。
df <- data.frame(x = c(1,2,3,4,5,6), y = c(7,4,9,2,6,7))
p <- ggplot(data = df, aes(x = x, y = y, colour = y)) +
geom_point() +
scale_color_viridis() +
theme_minimal()
# ggpubr does this for you
library(ggpubr)
leg <- get_legend(p)
as_ggplot(leg)