ggplot2,geom_point距离

时间:2018-05-28 14:45:02

标签: r ggplot2

我是R的新手。我试图制作我的数据的几何点图(性别研究的实验数据集)。数据结构有392个obs。和5变种变量是:

med_type(1:6),gen_type(1:17),quest_type(“Arosal”,“Plesure”,“Aesthetics”,“Imagination”),mean_m2(mean),SD_m2(sd)。

我做了这些情节:

ggplot(sum_tra_heterot_m, aes(x = gen_type , y = mean_m2)) +
  geom_point(aes(shape=as.factor(gen_type), color=as.factor(med_type)), size=2, position = position_dodge(width = 0.3))+
  scale_shape_manual(values=c(1:17),
                     name = "Genre_type",
                     breaks = c(1:17),
                     labels = c("hetero woman on top", "hetero Missionary", "hetero Doggy", "hetero Fellation",
                                "hetero Cunnilingus", "homo Fellation", "homo anal sex", "homo Cunnilingus",
                                "lesbian sex", "men masturbation", "woman masturbation", "naked woman",
                                "naked men", "men erection", "kissing", "detail of penetration",
                                "detail of genital"))+
  scale_color_manual(values=c('#ff0000','#e9ff00', '#32ff00', '#00ffff', '#4300ff', '#ff00fa'),
                     name = "Medium_type",
                     breaks = c(1:6),
                     labels = c("Foto","Sculpture","Painting","Graphic","Shunga","Hentai")) +
  ggtitle("Men - mean_of_evaluation_by_genre&medium_and_type_of_question") +
  theme(legend.position="bottom")+
  facet_wrap(~ quest_type, labeller = labeller(quest_type = labeller_names_2)
             )

结果如下:

here is result.

问题是个体“med_type”垂直排列并经常重叠。 是否可以将它们水平并排折叠?就像这里:

in these boxplot

1 个答案:

答案 0 :(得分:1)

你可以这样试试:

   ggplot()   + 
      geom_bar(data=sum_tra_heterot_m,  aes(x = gen_type , y = mean_m2, fill =  as.factor(med_type) ) ,
               stat = 'identity', position = 'dodge', alpha = 0.7) +
      faced_wrap(~as.factor(gen_type), ncol = 2)