使用 ggplot 抖动与分组描边/填充美学的点

问题描述 投票:0回答:1

我制作了一个带有我喜欢的误差线的散点图,但是我想在点周围添加白色轮廓以帮助区分它们。这造成了一系列问题。我的所有尝试要么创建错误/无输出,创建相同的图形而不改变点边框,删除抖动以便将点放置在单个文件中,或者删除所有美观的分组组织。 我能够让它单独使用这些元素(分组、美学等),但不能组合使用。那就是它破裂的时候。

df=read.csv('data.csv')

## data shaping ##
clusters=data.frame()
clusters = df[df$Person == '1',]
clusters = clusters %>% drop_na(Person)
cluster_imaging = clusters %>% drop_na(fourth)
cluster_imaging$cluster_SEC = as.factor(cluster_imaging$cluster_SEC)

cluster_imaging_NT <- cluster_imaging %>% 
  gather(key="ROIs", value = "standardized_value", first, second, third, fourth, fifth, sixth, seventh )
cluster_imaging_NT = cluster_imaging_NT[c("id","cluster_SEC","ROIs","standardized_value")]
  
cluster_acts_NT = cluster_imaging_NT[0:279,]
cluster_conn_NT = cluster_imaging_NT[280:651,]
#####


## scatter plot ##
conn_NT = ggplot(cluster_conn_NT, aes(x=ROIs, y=standardized_value, fill = cluster_SEC, color = cluster_SEC)) +
  #geom_boxplot(alpha = 0.3, notch = FALSE, outlier.color = "black") +
  ylab("y axis") +
  ggtitle("Title") +
  scale_y_continuous(limits=c(-6,4)) +
  scale_color_manual(values=c("gray","orange")) +
  geom_jitter(aes(group=cluster_SEC), shape=16, size=3, position=position_jitterdodge()) +
  geom_point(aes(group=cluster_SEC), shape=21, size=3, fill="white", color="black", position=position_jitterdodge()) +
  stat_summary(aes(group=cluster_SEC), fun = mean,
               fun.min = function(x) mean(x) - sd(x)/sqrt(length(x)),
               fun.max = function(x) mean(x) + sd(x)/sqrt(length(x)),
               geom = 'errorbar', width = 0.5, size = 1, color="black", position = position_dodge(0.75)) +
  theme_minimal() +
  theme(
    plot.title = element_text(size = 18, face = "bold", hjust = 0.5),
    axis.title = element_text(size = 14, face = "bold"),
    axis.text = element_text(size = 12),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank()
  )

conn_NT

Original figure that I would like to a white outline to each point

How it comes out if I try to edit it. I have tried a lot of different variations through chatgpt, but for each one, either the jitter is removed, or the aesthetics are not properly inherited and are lost in their grouping variations

ggplot2 grouping scatter-plot aesthetics jitter
1个回答
0
投票

如果没有最小的可重现示例,很难说这是否能解决您的问题,但请尝试:

df=read.csv('data.csv')

## data shaping ##
clusters=data.frame()
clusters = df[df$Person == '1',]
clusters = clusters %>% drop_na(Person)
cluster_imaging = clusters %>% drop_na(fourth)
cluster_imaging$cluster_SEC = as.factor(cluster_imaging$cluster_SEC)

cluster_imaging_NT <- cluster_imaging %>% 
  gather(key="ROIs", value = "standardized_value", first, second, third, fourth, fifth, sixth, seventh )
cluster_imaging_NT = cluster_imaging_NT[c("id","cluster_SEC","ROIs","standardized_value")]
  
cluster_acts_NT = cluster_imaging_NT[0:279,]
cluster_conn_NT = cluster_imaging_NT[280:651,]
#####


## scatter plot ##
conn_NT = ggplot(cluster_conn_NT, aes(x=ROIs, y=standardized_value, fill = cluster_SEC)) +
  ylab("y axis") +
  ggtitle("Title") +
  scale_y_continuous(limits=c(-6,4)) +
  scale_color_manual(values=c("gray","orange")) +
  geom_point(aes(group=cluster_SEC), shape=21, size=3, color="white", position=position_jitterdodge()) +
  stat_summary(aes(group=cluster_SEC), fun = mean,
               fun.min = function(x) mean(x) - sd(x)/sqrt(length(x)),
               fun.max = function(x) mean(x) + sd(x)/sqrt(length(x)),
               geom = 'errorbar', width = 0.5, size = 1, color="black", position = position_dodge(0.75)) +
  theme_minimal() +
  theme(
    plot.title = element_text(size = 18, face = "bold", hjust = 0.5),
    axis.title = element_text(size = 14, face = "bold"),
    axis.text = element_text(size = 12),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank()
  )

conn_NT
© www.soinside.com 2019 - 2024. All rights reserved.