简体   繁体   English

ggplot中的错误

[英]Error in ggplot

在此处输入图片说明

I am trying to make a ggplot. 我正在尝试做一个ggplot。 When I had shape in aesthetics, the code was working just fine. 当我在美学上有所建树时,代码就可以正常工作。 However, I need to put shape in geom_point() because I'm trying to reproduce a figure. 但是,我需要在geom_point()中放置形状,因为我正在尝试复制图形。 And when I added shape to geom_point() it gave me the following error: 当我将形状添加到geom_point()时,出现了以下错误:

Aesthetics must be either length 1 or the same as the data (6): shape 美学的长度必须为1或与数据(6)相同:shape

I've looked for other answers here but apparently, nothing seems to be working for me. 我在这里寻找其他答案,但显然,似乎没有任何工作对我有用。 Above I've provided with an image of what my data looks like. 在上面,我提供了一个数据外观的图像。 There are 17000 entries. 有17000个条目。

Below is my code: 下面是我的代码:

summarised_data <-ddply(mammals,c('mammals$chr','mammals$Species','mammals$chrMark'), 
function (x) c(median_rpkm = median(x$RPKM), median = median(x$dNdS)))

ggplot(summarised_data,aes(x = summarised_data$median_rpkm, y = summarised_data$median, 
color = summarised_data$`mammals$Species`)) + geom_smooth(se = FALSE, method = "lm") +
geom_point(shape = summarised_data$`mammals$chrMark`) + xlab("median RPKM") + ylab("dNdS")

  "ENSG00000213221", "ENSG00000213341", "ENSG00000213380", "ENSG00000213424", 
   "ENSG00000213533", "ENSG00000213551", "ENSG00000213619", "ENSG00000213626", 
  "ENSG00000213699", "ENSG00000213782", "ENSG00000213949", "ENSG00000214013", 
   "ENSG00000214338", "ENSG00000214357", "ENSG00000214367", "ENSG00000214517", 
    "ENSG00000214814", "ENSG00000215203", "ENSG00000215305",      "ENSG00000215367", 
   "ENSG00000215440", "ENSG00000215897", "ENSG00000221947", "ENSG00000222011", 
   "ENSG00000224051", "ENSG00000225830", "ENSG00000225921", "ENSG00000239305", 
   "ENSG00000239474", "ENSG00000239900", "ENSG00000241058", "ENSG00000242247", 
   "ENSG00000242612", "ENSG00000243646", "ENSG00000244038", "ENSG00000244045"), 
  class = "factor"), Species = structure(c(1L, 1L, 1L, 1L, 1L, 
   1L, 1L, 1L, 1L, 1L), .Label = c("Chimp", "Gori", "Human", "Maca", 
    "Mouse", "Oran"), class = "factor"), labs = structure(c(2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Chimp-A", "Chimp-X", 
    "Gori-A", "Gori-X", "Human-A", "Human-X", "Maca-A", "Maca-X", 
    "Mouse-A", "Mouse-X", "Oran-A", "Oran-X"), class = "factor"), 
     chrMark = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
      2L), .Label = c("A", "X"), class = "factor"), chr = structure(c(27L, 
      27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L), .Label = c("1", 
      "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", 
      "2", "20", "21", "22", "2a", "2A", "2b", "2B", "3", "4", 
        "5", "6", "7", "8", "9", "X"), class = "factor"), dN = c(3.00669, 
       3.27182, 7.02044, 1.01784, 3.0363, 2.32786, 4.92959, 3.03753, 
       3.0776, 1.02147), dS = c(3.15631, 5.87147, 3.13716, 2.05438, 
       4.10205, 5.24764, 4.2014, 3.18086, 5.4942, 3.02169), dNdS = c(0.9525965447, 
     0.5572403504, 2.2378329444, 0.4954487485, 0.7401908802, 0.4436013141, 
1.1733207978, 0.954939859, 0.5601543446, 0.3380459279), RPKM = c(31.6, 
13.9, 26.3, 9.02, 11.3, 137, 242, 1.05, 59.4, 10.1), Tau = c(0.7113820598, 
0.8391023102, 0.3185943152, 0.6887167806, 0.9120531859, 0.6254200542, 
0.7165302682, 0.7257435312, 0.2586613298, 0.6493567251), 
GC3 = c(0.615502, 0.622543, 0.393064, 0.490141, 0.461592, 
0.626407, 0.490305, 0.482853, 0.346424, 0.466484)), .Names = c("gene", 
 "Species", "labs", "chrMark", "chr", "dN", "dS", "dNdS", "RPKM", 
  "Tau", "GC3"), row.names = c(NA, 10L), class = "data.frame")

There's a few things wrong with your code and how ggplot handles non-standard evaluation, I'd recommend reading a ggplot tutorial or the docs. 您的代码以及ggplot如何处理非标准评估有一些问题,建议您阅读ggplot教程或文档。 Having a column called within summarised_data called 'mammals$species' and 'mammals$chrMark' is going to cause lots of problems. 有一个叫内列summarised_data称为'mammals$species''mammals$chrMark'将会导致很多问题。

If we change these to something more sensible... 如果我们将其更改为更明智的方式...

names(summarised_data)[names(summarised_data) == "mammals$species"] <- "mammals_species"
names(summarised_data)[names(summarised_data) == "mammals$chrMark"] <- "mammals_chrMark" 

We can make the ggplot code more friendly. 我们可以使ggplot代码更友好。 Note that shape has to been within aes , as you're mapping it to your data. 请注意,在将形状映射到数据时,形状必须在aes内。

ggplot(summarised_data, aes(x = median_rpkm, y = median)) + 
    geom_smooth(se = FALSE, method = "lm") +
    geom_point(aes(shape = mammals_chrMark,
                   color = mammals_species)) +
    xlab("median RPKM") + ylab("dNdS")

Hopefully this should work, or at least get you somewhere closer to an answer. 希望这应该起作用,或者至少使您更接近答案。

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

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