我想将灰色元素(小抖动点和小提琴)向右移动,这样它们就不会水平重叠(1)标记装置的形状(2)误差条。我相信position_nudge通常会起作用。但我已经在使用position_dodge了,我没有办法将position_nudge和position_dodge结合起来。
查看https://i.imgur.com/PJXoj0j.png
上的图片year <- c("1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th","1st","3rd","5th")
status <- c("P","P","P","P","P","P","P","P","P","P","P","P","P","P","P","P","P","P","P","P","P","P","P","P","P","P","P","P","P","P","Q","Q","Q","Q","Q","Q","Q","Q","Q","Q","Q","Q","Q","Q","Q","Q","Q","Q","Q","Q","Q","Q","Q","Q","Q","Q","Q","Q","Q","Q","R","R","R","R","R","R","R","R","R","R","R","R","R","R","R","R","R","R","R","R","R","R","R","R","R","R","R","R","R","R")
performance <- c(31,54,79,44,63,86,40,61,75,40,61,80,33,63,77,40,61,81,46,70,80,35,69,83,41,57,73,48,50,82,41,68,90,45,78,84,41,71,86,58,74,97,40,77,80,60,76,95,57,74,98,48,69,82,53,68,97,50,80,86,47,70,93,45,85,87,43,81,88,59,74,106,47,85,80,65,79,99,60,81,101,58,69,86,59,73,107,57,90,88)
tempdata <- data.frame (year, status, performance)
library(ggplot2)
#Establish the graph's general parameters
ggplot(data=tempdata, aes(x=year, y=performance, linetype=status, shape=status, size=status, color=status, fill=status))+
#Plot the raw, unaveraged data
geom_point(position=position_jitterdodge(dodge.width=0.9, jitter.height=0, jitter.width=0.06), size = 3.1,color="black", fill="gray50", alpha=0.3, show.legend=FALSE) +
#Plot a "violin"
geom_violin(fill="gray90", color="gray78", position=position_dodge(.9), alpha=0.1, size=0.9, scale="count", linetype="solid", width=.5, show.legend=FALSE) +
#Plot the Error Bars
stat_summary(fun.data=mean_cl_normal, position=position_dodge(.9), geom="errorbar", alpha=1.0, width=0.15) +
#Plot the mean markers
geom_point(stat = "summary", fun.y="mean", size=8.0, stroke = 2.4, alpha = 1, position=position_dodge(.9), fill=NA)+
#Create a list of the particular colors (line colors), fills (the fill colors for shapes), line types, and sizes/thicknesses.
scale_shape_manual(values=c(21, 24, 22))+
scale_size_manual(values=c(1.2, 1.2, 1.2)) +
scale_linetype_manual(values=c("solid", "solid", "solid"))+
scale_color_manual(values=c("blue", "red", "purple"))+
labs(x="Year", y="Performance", color="Status:", size="Status:", shape="Status:", fill="Status:", linetype="Status:")+
theme (panel.background=element_rect(fill = NA),panel.grid.major=element_line(color = NA), axis.line=element_line(size=1, color="black"), axis.ticks=element_line(color="black", size=1),axis.ticks.length=unit(5, "mm"), axis.title.x=element_text(margin = margin(t=20, r=0, b=30, l=0)),axis.title.y=element_text(margin = margin(t=0, r=20, b=0, l=0)),legend.position="bottom",legend.key=element_rect(fill=NA, color=NA, size=0.7),legend.key.width=unit(15, "mm"), text=element_text(size=rel(6.0)),legend.title=element_text(size=rel(4.5)), legend.text=element_text(size=rel(4.5)) )