简体   繁体   English

R:几何抖动图例不显示颜色和形状

[英]R: geom jitter legend does not show color and shape

I am trying to add jittered points which are colored by one column and shape is another column.我正在尝试添加由一列着色且形状为另一列的抖动点。 But I would also like them to have a black border.但我也希望它们有黑色边框。 Here is my code:这是我的代码:

library(ggplot2)
ggplot(dat, aes_string('Dim1', 'Dim2', fill = 'group', shape = 'library_type')) +
  geom_jitter(size = 5, width = 0.5, height = 0.5, alpha = 0.5) +
  scale_shape_manual(values = 21:22)

and this is the data这是数据

> dput(dat)
structure(list(Dim1 = c(2.2433841103276, -1.0303647643367, -4.63257218659317, 
12.7725858563145, -16.4870472079555, -5.89065982163346, -0.985970986489414, 
1.69578384100998, -2.33323980629837, 10.970166193839, 10.2024221295079, 
-10.6379213458339, 6.61075352370346, 1.812275158759, 10.2678441876134, 
-4.67706157029068, -10.9628763324062, 2.37916063010299, -2.14151717484391, 
6.17873762785995, 1.43081234633529, 1.32741938769424, -0.509525430802464, 
-4.41292716324723, 1.60391901671493, -15.1547632342616, 13.4221372479161, 
-4.37019587815201, -3.27147628128922, -4.56963254273331, 8.39020632445419, 
-4.44982148468888, 6.13996790587509, -4.35541678727066, -4.45309068024552, 
-4.8850178843776, -4.67206240952408, 10.6344032162389, 1.2055765265187, 
-6.33491040528214, 2.35641406714523, -1.22826982796585, 1.76740847766006, 
-2.20920897782242, -9.84016133606827, -5.30173302948868, 2.48082064330185, 
1.54127036273086, 2.07977007567489, -5.39448262513077), Dim2 = c(3.98269763950216, 
12.0263954735171, -4.84496339794291, 1.20136013988363, 1.08652106288778, 
-4.31233819957865, 11.9845406151186, 4.15871826175558, -9.5392115974058, 
-2.74255188938273, -0.358736511432059, -15.3434594535459, -12.2606137656797, 
4.04486766818868, -0.198577952217735, -4.82197031017435, -5.17211183544291, 
4.69237771991598, 17.0735327339541, 7.17819610599386, -16.039408054315, 
-15.9196313285459, -2.41221126552714, -13.5231040382017, -16.2335446738829, 
-10.523520793878, 1.19396928314077, -13.5673793220152, 5.73542228702413, 
-4.86651166912211, 4.80452457431661, -4.84282478328837, 7.13171783450948, 
-13.5823205375303, -4.81453689571512, -4.70398124691141, -4.82535823818339, 
-0.404572960101492, -15.9311927222837, 1.63539258006918, 4.59739128116476, 
12.1994825935732, 4.11349931720602, -9.66564210888041, 0.843212757147424, 
-4.86665901180399, -4.42825731273783, -15.8932298087705, 3.73198262218343, 
-4.54381355281962), sample_id = c("SRR1068687", "SRR1068788", 
"SRR1068808", "SRR1068832", "SRR1068855", "SRR1068880", "SRR1068905", 
"SRR1068929", "SRR1068953", "SRR1068977", "SRR1068999", "SRR1069024", 
"SRR1069048", "SRR1069074", "SRR1069097", "SRR1069121", "SRR1069141", 
"SRR1069166", "SRR1069188", "SRR1069209", "SRR1069231", "SRR1069255", 
"SRR1069279", "SRR1069303", "SRR1069328", "SRR1069352", "SRR1069376", 
"SRR1069400", "SRR1069421", "SRR1069445", "SRR1069466", "SRR1069490", 
"SRR1069514", "SRR1069539", "SRR1069564", "SRR1069590", "SRR1069614", 
"SRR1069638", "SRR1069666", "SRR1069690", "SRR1069714", "SRR1069734", 
"SRR1069758", "SRR1069778", "SRR1069802", "SRR1069826", "SRR1069850", 
"SRR1069871", "SRR1069895", "SRR1069919"), batch = c("GTEx_poly-A", 
"GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", 
"GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", 
"GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", 
"GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", 
"GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", 
"GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", 
"GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", 
"GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", 
"GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", 
"GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A", "GTEx_poly-A"), 
    study_id = c("GTEx", "GTEx", "GTEx", "GTEx", "GTEx", "GTEx", 
    "GTEx", "GTEx", "GTEx", "GTEx", "GTEx", "GTEx", "GTEx", "GTEx", 
    "GTEx", "GTEx", "GTEx", "GTEx", "GTEx", "GTEx", "GTEx", "GTEx", 
    "GTEx", "GTEx", "GTEx", "GTEx", "GTEx", "GTEx", "GTEx", "GTEx", 
    "GTEx", "GTEx", "GTEx", "GTEx", "GTEx", "GTEx", "GTEx", "GTEx", 
    "GTEx", "GTEx", "GTEx", "GTEx", "GTEx", "GTEx", "GTEx", "GTEx", 
    "GTEx", "GTEx", "GTEx", "GTEx"), library_type = c("poly-A", 
    "poly-A", "poly-A", "poly-A", "poly-A", "poly-A", "poly-A", 
    "poly-A", "poly-A", "poly-A", "poly-A", "poly-A", "poly-A", 
    "poly-A", "poly-A", "poly-A", "poly-A", "poly-A", "poly-A", 
    "poly-A", "poly-A", "poly-A", "poly-A", "poly-A", "poly-A", 
    "poly-A", "poly-A", "poly-A", "poly-A", "poly-A", "poly-A", 
    "poly-A", "poly-A", "poly-A", "poly-A", "poly-A", "poly-A", 
    "poly-A", "poly-A", "poly-A", "poly-A", "poly-A", "poly-A", 
    "poly-A", "poly-A", "poly-A", "poly-A", "poly-A", "poly-A", 
    "poly-A"), group = c("Esophagus", "Testis", "Skin", "Blood Vessel", 
    "Muscle", "Skin", "Testis", "Esophagus", "Stomach", "Breast", 
    "Breast", "Blood", "Skin", "Esophagus", "Adipose Tissue", 
    "Skin", "Liver", "Stomach", "Brain", "Prostate", "Esophagus", 
    "Esophagus", "Thyroid", "Spleen", "Esophagus", "Pancreas", 
    "Blood Vessel", "Spleen", "Adrenal Gland", "Skin", "Uterus", 
    "Skin", "Prostate", "Spleen", "Skin", "Skin", "Skin", "Adipose Tissue", 
    "Esophagus", "Heart", "Stomach", "Testis", "Esophagus", "Stomach", 
    "Heart", "Skin", "Colon", "Esophagus", "Esophagus", "Skin"
    )), row.names = c("SRR1068687", "SRR1068788", "SRR1068808", 
"SRR1068832", "SRR1068855", "SRR1068880", "SRR1068905", "SRR1068929", 
"SRR1068953", "SRR1068977", "SRR1068999", "SRR1069024", "SRR1069048", 
"SRR1069074", "SRR1069097", "SRR1069121", "SRR1069141", "SRR1069166", 
"SRR1069188", "SRR1069209", "SRR1069231", "SRR1069255", "SRR1069279", 
"SRR1069303", "SRR1069328", "SRR1069352", "SRR1069376", "SRR1069400", 
"SRR1069421", "SRR1069445", "SRR1069466", "SRR1069490", "SRR1069514", 
"SRR1069539", "SRR1069564", "SRR1069590", "SRR1069614", "SRR1069638", 
"SRR1069666", "SRR1069690", "SRR1069714", "SRR1069734", "SRR1069758", 
"SRR1069778", "SRR1069802", "SRR1069826", "SRR1069850", "SRR1069871", 
"SRR1069895", "SRR1069919"), class = "data.frame")

The plot that is generated, looks good but the legend does not show the corresponding colors:生成的 plot 看起来不错,但图例中没有显示对应的 colors:

在此处输入图像描述

How do I change the legend such that it shows the colors and the shape?如何更改图例以显示 colors 和形状?

I was able to use this comment github.com/tidyverse/ggplot2/issues/2322#issuecomment-342418340 to fix the issue.我能够使用此评论 github.com/tidyverse/ggplot2/issues/2322#issuecomment-342418340 来解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM