加载数据,绘制散点图:
library(ggplot2)
mtcars$gear <- as.character(mtcars$gear)
p <- ggplot(mtcars, aes(wt, mpg, color = gear))+
geom_point(size = 2.0)+
theme_bw()
nnn <- table(mtcars$gear)
data_text<-data.frame(label=c(paste0("n = ",nnn[1]),paste0("n = ",nnn[2]),paste0("n = ",nnn[3])),
x=c(5,5,5),
y=c(30,29,28),
color=unique(mtcars$gear))
p <- p+geom_text(data=data_text,
mapping=aes(x=x,y=y,label=label,color=color))
重新定义颜色:
p + scale_color_manual(values = c("red", "blue", "green"))
如果我想把P值显示在图的外面要怎么办呢
比如哪儿?上面的话可以将p作为标题显示即可