如何在R中正确定位标签?

jjjwad0x  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(110)

我正在为我的学校项目做这个图表,我必须把隐孢子虫这个名字用斜体印出来。有人知道如何把这个名字垂直向下移动吗?


的数据
编辑,我忘记添加代码,对不起

library(ggplot2)
v_pub <- 6 #CSPV1
v_gs <- 145 #CSPV1

pub <- 4858 #criptosporidium parvum
gs <- 69300 #criptosporidium parvum

vt_pub <- 0 #CSPV1 and TLR3
vt_gs <- 11 #CSPV1 and TLR3

#### GRAPH 1 ####

names <- c(rep("crypto",2), rep("kvirus",2), rep("TLR3",2))
source <- c(rep(c("pub","gs"),3))
numbers <- c(pub, gs, v_pub, v_gs, vt_pub, vt_gs)

df <- data.frame(names, source, numbers)

myplot <- ggplot(df, aes(names, numbers, fill=source)) +
  geom_bar(stat = "identity", position = 'dodge') +
  xlab("Exact words searched for") + ylab("Number of papers") +
  theme_bw() +
  #theme(panel.background = element_blank()) +
  scale_fill_discrete(name="Database",
                           breaks=c("gs", "pub"),
                           labels=c("Google Scholar", "PubMed")) +
  geom_text(aes(label = numbers, group=source), position=position_dodge(width=0.9), vjust=-0.2, size=4) +
  scale_x_discrete(breaks = c("crypto","kvirus","TLR3"),
                   labels = c(expression(italic("Criptosporidium \nparvum")),"CSPV1","CSPV1 TLR3"))
myplot

字符串

i86rm4rw

i86rm4rw1#

您可以使用固定的x轴绘制相同的图,如下所示:

library(ggplot2)
library(ggtext)

data.frame(word = rep(c('<i>Criptosporidium<br>parvum</i>', 
                        'CSPV1', 'CSPV1 TLR3'), each = 2),
                 n= c(69300,4858, 145, 6, 11, 0),
                 Database = rep(c('Google Scholar', 'PubMed'), 3),
                 check.names = FALSE) |>
  ggplot(aes(word, n)) +
  geom_col(aes(fill = Database), position = 'dodge') +
  geom_text(aes(label = n, group = Database), vjust = -0.2,
            position = position_dodge(0.9)) +
  labs(x = 'Exact words searched for', y = 'Number of papers') +
  theme_bw() +
  theme(axis.text.x = element_markdown())

字符串


的数据

相关问题