library(ggplot2)library(gcookbook) # Load gcookbook for the tg data setggplot(tg, aes(x = dose, y = length, shape = supp)) + geom_line() + geom_point(size = 4) # Make the points a little larger
ggplot(tg, aes(x = dose, y = length, colour = supp)) + geom_line(linetype = "dashed") + geom_point(shape = 22, size = 3, fill = "white")
# 创建一个“并排偏移”的位置调整器:# 用于在同一剂量 dose 下,不同组 supp 的线/点彼此错开,避免重叠pd <- position_dodge(0.2)# 开始作图:数据集是 tg# x 轴:dose# y 轴:length# 填充颜色(用于区分组):suppggplot(tg, aes(x = dose, y = length, fill = supp)) + # 画折线:每个组会根据 position = pd 做并排偏移 geom_line(position = pd) + # 画散点:shape = 21 表示点形状为可填充的点(边框+填充) # size = 3 控制点大小 # position = pd 让散点也跟折线使用相同的并排规则 geom_point(shape = 21, size = 3, position = pd) + # 手动指定填充颜色:supp 的取值将对应到这些颜色 # 这里把两组分别设为黑色和白色 scale_fill_manual(values = c("black","white"))
发表评论