小编Tor*_*von的帖子

为复杂的绘图构建手动图例

我无法弄清楚如何手动设置此图的图例.我真正想要的只是右边一个简单的图例,它使用了三种颜色并且每个颜色旁边都有一个名称.

在此输入图像描述

当前代码如下所示:

a <-c("S1","S2","S3","S4","S5","S6","S7","S8","S9") #names
b <-c(0.23,0.26,0.55,0.56,0.36,0.23,0.18,0.06,0.04) #mean t0
c <-c(0.64,0.6,0.81,1.4,0.89,0.55,0.48,0.22,0.09) #mean t1
d <-c(0.20,0.23,0.52,0.53,0.33,0.20,0.15,0.04,0.03) #SD low t0
e <-c(0.26,0.29,0.58,.59,0.39,0.26,0.21,0.08,0.05) #SD high t0
f <-c(0.67,0.63,0.86,1.44,0.93,0.59,0.51,0.25,0.10) #SD high t1
g <-c(0.61,0.57,0.78,1.36,0.85,0.53,0.45,0.19,0.08) #SD low t1
h <-c(0.41,0.34,0.26,0.84,0.53,0.32,0.30,0.16,0.05) #absolute change

data <- data.frame(a,b,c,d,e,f,g,h)

ggplot(data=data,aes(a)) + 
  geom_bar(stat="identity", aes(y=h),fill="#62c76b",colour="#333333")+ #green
  geom_line(aes(y=b,group=1),size=1.0,colour="#f04546") +   #red
  geom_point(aes(y=b),size=3, colour="#f04546") +           #red
  geom_errorbar(aes(ymin=d, ymax=e), colour="#f04546", width=0.1, size=.8) + 
  geom_line(aes(y=c,group=1),size=1.0,colour="#3591d1") +   #blue 
  geom_point(aes(y=c),size=3, colour="#3591d1") +           #blue
  geom_errorbar(aes(ymin=f, ymax=g), colour="#3591d1", width=0.1, size=.8) + 
  ylab("Symptom severity") + xlab("PHQ-9 symptoms") +
  ylim(0,1.6) +
  theme_bw() …
Run Code Online (Sandbox Code Playgroud)

r data-visualization ggplot2

67
推荐指数
2
解决办法
11万
查看次数

ggplot2:使用内置字体将图另存为EPS

一家期刊希望我将这些数字作为EPS文件提交。使用ggplot2将它们从R导出为EPS文件,然后在Adobe Illustrator中打开EPS文件,这告诉我“系统上找不到字体”。

我该如何解决这个问题?这是我当前使用的语法。

library(ggplot2)    
a <-c("Sad Mood", "Cognition", "Fatigue", "Interest Loss", "Slowed", "Self-blame", "Suicidal Ideation", "Early insomnia", "Appetite", "Late insomnia", "Agitated", "Weight", "Middle insomnia", "Hypersomnia", "Age", "Sex")
b <-c(20.7,16.5,13.8,13.1,8.8,6.4,6.1,3.6,3.0,2.5,2.1,1.3,0.9,0.7,0.4,0.1)
c <-c(17.90,13.64,11.36,10.72,6.99,4.60,4.68,2.38,2.09,1.65,1.35,0.76,0.47,0.24,0.15,0.03) #lower CI
d <-c(23.47,19.27,16.28,15.74,10.64,8.20,7.95,5.07,4.21,3.63,2.99,2.22,1.59,1.62,0.95,0.31) #upper CI

data <- data.frame(a,b,c,d)
data1 <- transform(data, a = reorder(a, order(b, decreasing = FALSE)))
data1$label <-sprintf("%.1f", data1$b)

ggplot(data1, aes(x=as.factor(a), y=b, order=a))+
  geom_bar(stat="identity",fill='#888888',colour='#888888') +theme_bw() +coord_flip() +
  ylab("Relative importance estimation in %") +xlab("") +
  geom_errorbar(aes(ymin=c, ymax=d), width=.3, size=.5)+ 
  geom_text(aes(label=label), size=4.5, vjust=.4,hjust=-1.5)+
  scale_y_continuous(limits = c(-0, 25))+
  theme(axis.text.x …
Run Code Online (Sandbox Code Playgroud)

fonts r ggplot2

5
推荐指数
1
解决办法
1982
查看次数

标签 统计

ggplot2 ×2

r ×2

data-visualization ×1

fonts ×1