gpt4 book ai didi

r - 照片与 r 中的图形对齐

转载 作者:行者123 更新时间:2023-12-03 11:36:59 29 4
gpt4 key购买 nike

首先我认为我需要在 powerpoint 中手动进行,然后我想可以尝试使用 R,如果有解决方案。这是我的示例数据:

set.seed(123)
myd<- expand.grid('cat' = LETTERS[1:5], 'cond'= c(F,T), 'phase' = c("Interphase", "Prophase", "Metaphase", "Anaphase", "Telophase"))
myd$value <- floor((rnorm(nrow(myd)))*100)
myd$value[myd$value < 0] <- 0

require(ggplot2)
ggplot() +
geom_bar(data=myd, aes(y = value, x = phase, fill = cat), stat="identity",position='dodge') +
theme_bw()

以下是输出的样子:
enter image description here

jpeg 图像可以随机生成(用于演示示例)或链接中的示例图:

Interphase prophase , metaphase , anaphase , telophase

编辑:

建议@bapste

enter image description here

最佳答案

我现在将使用 ggtext 包执行此操作。这在概念上类似于解决方案 suggested here但是在包装中完成了艰苦的工作。

library(tidyverse)
library(ggtext)

set.seed(123)

data <- expand.grid(
cat = LETTERS[1:5],
cond= c(FALSE, TRUE),
phase = c("Interphase", "Prophase", "Metaphase", "Anaphase", "Telophase")
) %>%
mutate(
value = floor(rnorm(n())*100),
value = ifelse(value < 0, 0, value)
)

# images from: http://www.microbehunter.com/mitosis-stages-of-the-lily/

labels <- c(
Interphase = "<img src='img/interphase.jpg' width='60' /><br>Interphase",
Prophase = "<img src='img/prophase.jpg' width='60' /><br>Prophase",
Metaphase = "<img src='img/metaphase.jpg' width='60' /><br>Metaphase",
Anaphase = "<img src='img/anaphase.jpg' width='60' /><br>Anaphase",
Telophase = "<img src='img/telophase.jpg' width='60' /><br>Telophase"
)

ggplot(data, aes(phase, value, fill = cat)) +
geom_col(position = "dodge") +
scale_x_discrete(name = NULL, labels = labels) +
theme(axis.text.x = element_markdown(lineheight = 1.2))



reprex package 创建于 2020-01-29| (v0.3.0)

关于r - 照片与 r 中的图形对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14070953/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com