我已经使用ggplot(下面带有DF1数据集)创建了一个图。我想在此情节中添加两个内容:
感谢您的建议!
ID<-rep(c(1,2),each=6)
START <- c(0, 42,57,300,520,710, 0,31,56,85,120,300)
END <- c(42,57,300,520,710,711,31,56,85,120,300,301)
TYPE <- c("S","NR","R","NR","R","R","S","R","NR","R","NR","NR")
DF1 <-data.frame(ID,START,END,TYPE)
DF1
# converting ID from numeric to factor
DF1 %<>%
dplyr::mutate(ID = factor(ID))
ggplot(DF1,aes(y=ID,yend=ID,x=START,xend=END,color=TYPE))+
geom_segment(aes(y=ID,yend=ID,x=START,xend=END),size=6,lineend= "butt")
DF.SYMBOL 数据集,可将点和符号添加到绘图中
ID<-rep(c(1,2),each=2)
EVENT <- rep(c("TBR","PBR"))
TIME <- c(90, 220,120,200)
DF.SYMBOL<-data.frame(ID,EVENT,TIME)
DF.LINE 数据集,以在每个ID垂直线上方的图例中添加带有CONC的图例中的垂直线
ID <- c(1,2)
TIME <- c(400, 265)
CONC <- c(23,97)
DF.LINE<-data.frame(ID,TIME, CONC)
这是所需的图(在powerpoint上编辑):基于DF.SYMBOL数据集的符号和带基于DF.LINE数据集的值的黑线。
答案 0 :(得分:3)
这应该做到。我使用geom_errorbarh
作为垂直线-我不知道有一种更好的方法来使水平线上的垂直线以离散比例显示。为了更好地控制厚度,您可以考虑将geom_segment
更改为geom_rect
。
DF.SYMBOL$ID = factor(DF.SYMBOL$ID)
DF.LINE$ID = factor(DF.LINE$ID)
ggplot(DF1,aes(y=ID))+
geom_segment(aes(yend=ID, x=START, xend=END, color = TYPE),size=6,lineend= "butt") +
geom_point(data = DF.SYMBOL, aes(x = TIME, fill = EVENT, shape = EVENT), size = ) +
scale_shape_manual(values = c(21, 24)) +
scale_fill_manual(values = c("red", "yellow")) +
geom_errorbarh(data = DF.LINE, aes(xmin = TIME, xmax = TIME), height = 0.1) +
geom_text(data = DF.LINE, aes(x = TIME, label = CONC), vjust = -1.5)