本文介绍了更新Rstudio 1.1.383之后,我有ggplot出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我刚刚将RStudio从0.99.896更新为1.1.383(最新版本),工作在Ubuntu 16.4上。 在更新之前,我写了一个分析脚本其中我使用 akima 和 ggplot2 绘制了一个数据集的插值。 这是脚本: require(akima)#this包内插值 require( (%P(P10,P11,P12c))&! Class_size == 0.3) Space2 & Class_size == 0.3 & Time ==D) Space< - rbind(Space1,Space2) duplicate(Space) attach(Space) fld< - (空格,interp(x = Longitud.E。,y = Latitude.S。,z = Chla2017_mean,duplicate =mean)) gdat< - interp2xyz(fld,data.frame = TRUE) ggplot(gdat)+ aes(x = x,y = y,z = z,fill = z)+ geom_tile()+ #coord_equal()+ geom_contour(color =white,alpha = 0.5)+ scale_fill_distiller(palette =Spectral,na.value =白色,限制= c(0,0.35))+ scale_y_reverse()+ theme_bw()+ ggtitle(叶绿素a(班级规模0.3-2.7微米))+ ylab(Latitude S)+ xlab(Longitude E)+ labs(fill =Chl-a(mg / m3))+ geom_point(data = Space, mapping = aes(Longitud.E。,Latitude.S。),shape = 1) 真的很好,但更新后,我有这个错误按摩: 在FUN(X [[i]]中的错误,.. .. 。):找不到对象'z' 这些是gdat和fld的结构: str(gdat)'data.frame':1600 obs。 3个变量: $ x:数37.3 37.3 37.4 37.4 37.4 ... $ y:数45.7 45.7 45.7 45.7 45.7 ... $ z:数量不适用不适用不适用不适用不适用不适用不适用不适用... > str(fld)列表3 $ x:num [1:40] 37.3 37.3 37.4 37.4 37.4 ... $ y:num [1:40] 45.7 45.8 45.8 45.9 45.9 ... $ z:num [1:40,1:40]不适用不适用不适用不适用不适用不适用不适用不适用... ... 这里以一个我称之为ChlaMD2的数据集的子表为例 > ;输入(ChlaMD2)结构(列表(站点=结构(c(1L,2L,3L,4L,5L,6L, 7L,9L,9L,10L,10L,8L,11L,12L, 13L,13L,14L,14L,14L, 15L,15L,16L,17L,18L,20L,20L,20L,20L,20L,20L,20L,20L, 20L,20L,20L, 20L,20L,20L,20L,20L,20L,20L,21L,21L,21L, 21L,21L,21L,22L,22L,22L,22L,22L,22L,22L,22L,22L,22L, 22L,22L,22L,22L,22L,22L,22L,22L,23L,23L,23L,23L,23L, 23L,23L,19L),标签= c(C12 C23,C27,C30,C35,,C53,C57,D1,D11,D12,D2,D3,D4 D5D6D7D8D9H1H13H17H18H19H2 H20,,H21,H3,H4,H5,H7,P10,P11,P12,P12c,class = ),时间=结构(c(2L,2L,2L,2L,2L,2L,2L,2L,2L,2L, 2L,2L,3L,2L,2L,2L,2L, 2L,2L,2L,2L,2L,2L,3L,3L, 3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L, 3L,3L,3L,3L,3L,3L,3L,3L,2L,2L,2L,2L,2L,2L, 2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,标签= c(,D,N),class =factor), Class_size = c(0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3, 0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3, 0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,25 ,25,25, 25,25,25,2.7,2.7,2.7,2.7,2.7,2.7,0.3,0.3,25,25, 2.7,2.7,0.3,0.3,0.3,0.3 ,0.3,0.3,25,25,25,25,25, 25,2.7,2.7,2.7,2.7,2.7,2.7,0.3,0.3,0.7,25,25, 2.7,2.7 ,0.3),Depth = c(1,1,10,10,40,10,10,10,50, 10.1,25.4,10,5.5,10,10,35,10,15, 10,10,10,10,10,10,10,100,150,30,40,60,10,100,150,30,40,60,$ b $ 10,100,150,30, 40,60,10,60,10,60,10,60,10,100, 20,40,60,80,10,100,20,40,60,80,10,100,20, 40, 60,80,10,50,10,10,50,10,50,30),Latitude.S。 = C(46.7861666666667, 46.8812166666667,46.7836333333333,46.8828666666667,46.7471666666667, 46.9049166666667,47.021,46.6074,46.6074,46.8082333333333, 46.8082333333333,46.80335,46.7286833333333,46.7286833333333, 46.8039666666667,46.8039666666667 ,46.80175,47.80175,48.80175, 46.8032166666667,46.8032166666667,46.7251666666667,46.85855, 46.8078333333333,46.7498,46.7498,46.7498,46.7498,46.7498, 46.7498,46.7498,46.7498,46.7498,46.7498,46.7498 ,46.7498, 46.7498,46.7498,46.7498,46.7498,46.7498,46.7498,46.74985, 46.74985,46.74985,46.74985,46.74985,46.74985,46.74985, 46.74985,46.74985,46.74985,46.74985,46.74985 ,46.74985, 46.74985,46.74985,46.74985,46.74985,46.74985,46.74985, 46.74985,46.74985,46.74985,46.74985,46.74985,46.74985, 46.74985,46.74985,46.74985,46.74985,46.74985,46.74985 , 45.7494),Longitud.E 。 = C(37.8826666666667,37.8811166666667, 38.0012833333333,37.91525,37.799,37.5724833333333,37.942, 37.9704,37.9704,38.0699666666667,38.0699666666667,37.98505, 37.7509666666667,37.7509666666667,37.9852,37.9852,37.8366166666667, 38.8366166666667,39.8366166666667,37.9857833333333,37.9857833333333, 38.07365,38.0585833333333,38.0727,38.5003666666667,38.5003666666667, 38.5003666666667,38.5003666666667,38.5003666666667,38.5003666666667, 38.5003666666667,38.5003666666667,38.5003666666667,38.5003666666667, 38.5003666666667,38.5003666666667,38.5003666666667,38.5003666666667, 38.5003666666667,38.5003666666667,38.5003666666667,38.5003666666667, 38.3001666666667,38.3001666666667,38.3001666666667,38.3001666666667, 38.3001666666667,38.3001666666667,38.1007,38.1007,38.1007, 38.1007,38.1007,38.1007,38.1007,38.1007,38.1007,38.1007, 3 (b),b。,b。,b。,b。,b。,b。,b。,b。,b。,b。,b。,b。,b。,b。,b。,b。,b。 0.946057215301194, -0.735763592835187,-0.721930224211009,-0.743435200089837, -1.02003987926121,-0.738912060933631,-0.685963597586669, -0.997636902853672,-0.643630322972336,-0.669377265328764, -0.664963978099764,-0.912380457471698 ,-0.654771449880747, -0.658883141830635,-0.333377057394302,-0.834435774509827, -0.608164121834402,-0.601054836622574,-0.601054836622574, -0.433924828117425,-0.423546688240005,-0.674419537322733, -0.750411161442486, -0.725080930111579,-0.935910556294799, -0.817942131498285,-1.02383834665726,-0.892403896151859, -0.808467536615044,-0.884840160205845,-1.0603345408323, -1.0786705 2090535,-1.11040448340463,-1.09645994731746, -1.06683594257792,-1.07149832401568,-1.00312051998841, -0.892390049851206,-1.0156562515399,-0.845436000058676, -0.77307928664173,-0.898018165946667,-0.848289249417617, -0.810493908599841,-1.09301597219965,-1.10655481387971, -0.85745513293466,-0.876433420431031,-0.661357685769219, -0.86379511602107,-0.671973895984953,-0.612517223135917, -0.53238050140151,-0.766900709336143,-1.07529825124183, -1.11868087013396,-1.09598460061627,-1.0797581766586,-1.09630430291743, -1.10204233962275,-0.773288219842876,-0.897549491056236, -0.781499768825993,-0.644915965716444,-0.612259094442557, -0.827935663448589,-0.410489183767067 ,-0.487960331090299, -0.439197104297121,-1.06520799675057,-1.08484214393861, -0.548500319979572,-0.559953402295738,-0.62854993920894 )),.Names = c(Station,Time, C lass_size,Depth,Latitude.S。,Longitud.E,Chla2017_mean),row.names = c(NA, 74L),class =data。框架) 解决方案 geom_point 在最后一行是从第一个aes继承aes,它具有 z 作为填充。我们需要使用 inherit.aes = FALSE : ggplot(gdat )+ aes(x = x,y = y,z = z,fill = z)+ geom_tile()+ geom_contour(color =white,alpha = 0.5)+ geom_point(data = Space,mapping = aes(Longitud.E。,Latitude.S。), shape = 1,inherit.aes = FALSE)+ scale_fill_distiller(palette =Spectral ,na.value =white)+ scale_y_reverse()+ theme_bw()+ ggtitle(Chlorophyll-a(class size 0.3-2.7 um))+ ylab(Latitude S)+ xlab(Longitude E)+ labs(fill =Chl-a(mg / m3)) pre> 对您的代码进行小的更改: ,主题,实验室等。 我删除了 scale_fill_distiller 中的限制 I just updated RStudio from version 0.99.896 to 1.1.383 (the latest) working on Ubuntu 16.4.Before to update, I wrote a script of analysis in which I plot an interpolation of a data set using akima and ggplot2.this is the script:require(akima) #this package interpolate valuesrequire(ggplot2)Space1 <- subset(x = ChlaMD2, Depth <= 14 & !(Station %in% c("P10","P11","P12c")) & Class_size == 0.3) Space2 <- subset(x = ChlaMD2, Depth <= 14 & Station %in% c("P10","P11") & Class_size == 0.3 & Time == "D") Space <- rbind(Space1,Space2)duplicated(Space)attach(Space)fld <- with(Space, interp(x = Longitud.E., y = Latitude.S., z = Chla2017_mean,duplicate = "mean"))gdat <- interp2xyz(fld, data.frame=TRUE)ggplot(gdat) + aes(x = x, y = y, z = z, fill = z) + geom_tile() + #coord_equal() + geom_contour(color = "white", alpha = 0.5) + scale_fill_distiller(palette="Spectral", na.value="white",limits=c(0,0.35)) + scale_y_reverse()+ theme_bw()+ ggtitle("Chlorophyll-a (class size 0.3-2.7 um)")+ ylab("Latitude S") + xlab("Longitude E")+ labs(fill = "Chl-a (mg/m3)")+ geom_point(data = Space, mapping = aes(Longitud.E.,Latitude.S.),shape=1)It worked really well, but after the updating I have this error massage:Error in FUN(X[[i]], ...) : object 'z' not foundthese are the structures of gdat and fld:str(gdat)'data.frame': 1600 obs. of 3 variables: $ x: num 37.3 37.3 37.4 37.4 37.4 ... $ y: num 45.7 45.7 45.7 45.7 45.7 ... $ z: num NA NA NA NA NA NA NA NA NA NA ...> str(fld)List of 3 $ x: num [1:40] 37.3 37.3 37.4 37.4 37.4 ... $ y: num [1:40] 45.7 45.8 45.8 45.9 45.9 ... $ z: num [1:40, 1:40] NA NA NA NA NA NA NA NA NA NA ...Here as an example a subtable of my dataset that I called ChlaMD2> dput(ChlaMD2)structure(list(Station = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 9L, 9L, 10L, 10L, 8L, 11L, 12L, 13L, 13L, 14L, 14L, 14L, 15L, 15L, 16L, 17L, 18L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 21L, 21L, 21L, 21L, 21L, 21L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 19L), .Label = c("C12", "C23", "C27", "C30", "C35", "C53", "C57", "D1", "D11", "D12", "D2", "D3", "D4", "D5", "D6", "D7", "D8", "D9", "H1", "H13", "H17", "H18", "H19", "H2", "H20", "H21", "H3", "H4", "H5", "H7", "P10", "P11", "P12", "P12c"), class = "factor"), Time = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("", "D", "N"), class = "factor"), Class_size = c(0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 25, 25, 25, 25, 25, 25, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 0.3, 0.3, 25, 25, 2.7, 2.7, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 25, 25, 25, 25, 25, 25, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 0.3, 0.3, 0.7, 25, 25, 2.7, 2.7, 0.3), Depth = c(1, 1, 10, 10, 40, 10, 10, 10, 50, 10.1, 25.4, 10, 10.5, 10, 10, 35, 10, 15, 15, 10, 107, 9.8, 10, 10, 10, 100, 150, 30, 40, 60, 10, 100, 150, 30, 40, 60, 10, 100, 150, 30, 40, 60, 10, 60, 10, 60, 10, 60, 10, 100, 20, 40, 60, 80, 10, 100, 20, 40, 60, 80, 10, 100, 20, 40, 60, 80, 10, 50, 10, 10, 50, 10, 50, 30), Latitude.S. = c(46.7861666666667, 46.8812166666667, 46.7836333333333, 46.8828666666667, 46.7471666666667, 46.9049166666667, 47.021, 46.6074, 46.6074, 46.8082333333333, 46.8082333333333, 46.80335, 46.7286833333333, 46.7286833333333, 46.8039666666667, 46.8039666666667, 46.80175, 47.80175, 48.80175, 46.8032166666667, 46.8032166666667, 46.7251666666667, 46.85855, 46.8078333333333, 46.7498, 46.7498, 46.7498, 46.7498, 46.7498, 46.7498, 46.7498, 46.7498, 46.7498, 46.7498, 46.7498, 46.7498, 46.7498, 46.7498, 46.7498, 46.7498, 46.7498, 46.7498, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 46.74985, 45.7494), Longitud.E. = c(37.8826666666667, 37.8811166666667, 38.0012833333333, 37.91525, 37.799, 37.5724833333333, 37.942, 37.9704, 37.9704, 38.0699666666667, 38.0699666666667, 37.98505, 37.7509666666667, 37.7509666666667, 37.9852, 37.9852, 37.8366166666667, 38.8366166666667, 39.8366166666667, 37.9857833333333, 37.9857833333333, 38.07365, 38.0585833333333, 38.0727, 38.5003666666667, 38.5003666666667, 38.5003666666667, 38.5003666666667, 38.5003666666667, 38.5003666666667, 38.5003666666667, 38.5003666666667, 38.5003666666667, 38.5003666666667, 38.5003666666667, 38.5003666666667, 38.5003666666667, 38.5003666666667, 38.5003666666667, 38.5003666666667, 38.5003666666667, 38.5003666666667, 38.3001666666667, 38.3001666666667, 38.3001666666667, 38.3001666666667, 38.3001666666667, 38.3001666666667, 38.1007, 38.1007, 38.1007, 38.1007, 38.1007, 38.1007, 38.1007, 38.1007, 38.1007, 38.1007, 38.1007, 38.1007, 38.1007, 38.1007, 38.1007, 38.1007, 38.1007, 38.1007, 37.9009666666667, 37.9009666666667, 37.9009666666667, 37.9009666666667, 37.9009666666667, 37.9009666666667, 37.9009666666667, 37.2994833333333), Chla2017_mean = c(-0.946057215301194, -0.735763592835187, -0.721930224211009, -0.743435200089837, -1.02003987926121, -0.738912060933631, -0.685963597586669, -0.997636902853672, -0.643630322972336, -0.669377265328764, -0.664963978099764, -0.912380457471698, -0.654771449880747, -0.658883141830635, -0.333377057394302, -0.834435774509827, -0.608164121834402, -0.601054836622574, -0.601054836622574, -0.433924828117425, -0.423546688240005, -0.674419537322733, -0.750411161442486, -0.725080930111579, -0.935910556294799, -0.817942131498285, -1.02383834665726, -0.892403896151859, -0.808467536615044, -0.884840160205845, -1.0603345408323, -1.07867052090535, -1.11040448340463, -1.09645994731746, -1.06683594257792, -1.07149832401568, -1.00312051998841, -0.892390049851206, -1.0156562515399, -0.845436000058676, -0.77307928664173, -0.898018165946667, -0.848289249417617, -0.810493908599841, -1.09301597219965, -1.10655481387971, -0.85745513293466, -0.876433420431031, -0.661357685769219, -0.86379511602107, -0.671973895984953, -0.612517223135917, -0.53238050140151, -0.766900709336143, -1.07529825124183, -1.11868087013396, -1.09598460061627, -1.0797581766586, -1.09630430291743, -1.10204233962275, -0.773288219842876, -0.897549491056236, -0.781499768825993, -0.644915965716444, -0.612259094442557, -0.827935663448589, -0.410489183767067, -0.487960331090299, -0.439197104297121, -1.06520799675057, -1.08484214393861, -0.548500319979572, -0.559953402295738, -0.62854993920894 )), .Names = c("Station", "Time", "Class_size", "Depth", "Latitude.S.", "Longitud.E.", "Chla2017_mean"), row.names = c(NA, 74L), class = "data.frame") 解决方案 geom_point on the last line is inheriting aes from first aes which has z as fill. We need to use inherit.aes = FALSE:ggplot(gdat) + aes(x = x, y = y, z = z, fill = z) + geom_tile() + geom_contour(color = "white", alpha = 0.5) + geom_point(data = Space, mapping = aes(Longitud.E., Latitude.S.), shape = 1, inherit.aes = FALSE) + scale_fill_distiller(palette = "Spectral", na.value = "white") + scale_y_reverse() + theme_bw() + ggtitle("Chlorophyll-a (class size 0.3-2.7 um)") + ylab("Latitude S") + xlab("Longitude E") + labs(fill = "Chl-a (mg/m3)") Minor changes to your code:I prefer geoms first then scale, theme, labs, etc. I removed the limits in scale_fill_distiller 这篇关于更新Rstudio 1.1.383之后,我有ggplot出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-27 21:54