更新到ggplot 2.2.0后的情节错误 - 未知的美学

时间:2016-11-22 01:51:50

标签: r plot ggplot2

我最近更新到ggplot 2.2.0,现在在绘制geom_ribbon时收到错误。

在更新之前,我能够使用下面的代码制作一个没有错误的情节。

ggplot(df, aes(x=dose,y=probability, group=model))+

  geom_ribbon(aes(ymin=Lower,ymax=Upper,x=dose,y=probability,
                fill=model, col=model,alpha=2))+

  #log scale transformation - not related to problem
  scale_x_log10(breaks = 10^(-1:10),
                labels = trans_format("log10", math_format(10^.x)))

图形仍然是创建的,并且在更新之前就像它一样,但错误令人不安:

  

警告:忽略未知的美学:y

enter image description here

发生了什么事?

数据:

df<- structure(list(dose = c(1.0000001, 1.04737100217022, 1.09698590648847,1.14895111335032, 1.20337795869652, 1.26038305255123, 1.32008852886009,1.38262230716338, 1.44811836666478, 1.51671703328309, 61.5098612858473,64.4236386159454, 67.4754441930906, 70.6718165392165, 74.0196039119089,77.525978976861, 81.1984541753771, 85.0448978198478, 89.073550951683,93.2930449978201, 97.7124202636365, 1.0000001, 1.04737100217022,1.09698590648847, 1.14895111335032, 1.20337795869652, 1.26038305255123,1.32008852886009, 1.38262230716338, 1.44811836666478, 1.51671703328309,1.58856528030183, 61.5098612858473, 64.4236386159454, 67.4754441930906,70.6718165392165, 74.0196039119089, 77.525978976861, 81.1984541753771,85.0448978198478, 89.073550951683, 93.2930449978201, 97.7124202636365), probability = c(0.0683943049971327, 0.0710733028282005, 0.0738489183840793,0.0767239767983856, 0.0797013335438264, 0.082783870188366, 0.0859744897217715,0.0892761114342676, 0.0926916653299095, 0.0962240860584173, 0.743504045976579,0.75130105881223, 0.758937902621934, 0.766413150670434, 0.773725705643206,0.780874788821986, 0.787859928409335, 0.794680947124687, 0.801337949191767,0.807831306833738, 0.814161646387909, 0.161017067404578, 0.165316271302969,0.169707045836242, 0.174190101595605, 0.178766085953008, 0.18343557936714,0.188199091673034, 0.193057058367325, 0.198009836902001, 0.203057703000276,0.208200847008982, 0.759823400528161, 0.765522522870503, 0.771127146329567,0.776636892824514, 0.782051489414933, 0.787370765189199, 0.792594648019461,0.797723161201064, 0.80275641999383, 0.807694628082067, 0.812538073969653), Lower = c(0.0489957622300627, 0.0512892097278028, 0.0536806652461835,0.0561736016693977, 0.0587715542040369, 0.0614781156917885, 0.0642969312493771,0.0672316921917047, 0.0702861291937286, 0.0734640046465117, 0.706935463139687,0.714658499904115, 0.722256523605252, 0.729727740877861, 0.737070539882659,0.744283492600218, 0.751365356123786, 0.758315072991922, 0.765131770607941,0.771814759798154, 0.778363532564622, 0.124633336052869, 0.128654903811229,0.132781815255996, 0.137015420180004, 0.141356998770501, 0.145807755618442,0.150368813594647, 0.155041207607635, 0.159825878259527, 0.16472366541804,0.169735301724211, 0.734177476670615, 0.739796217703284, 0.745330000997808,0.750779046297187, 0.756143591270489, 0.761423892682964, 0.766620227597355,0.771732894552258, 0.776762214675666, 0.781708532702237, 0.786572217871554), Upper = c(0.0877928477642027, 0.0908573959285981, 0.0940171715219751,0.0972743519273734, 0.100631112883616, 0.104089624684944, 0.107652048194166,0.11132053067683, 0.115097201466091, 0.118984167470323, 0.780072628813471,0.787943617720345, 0.795619281638616, 0.803098560463007, 0.810380871403752,0.817466085043754, 0.824354500694884, 0.831046821257452, 0.837544127775594,0.843847853869323, 0.849959760211196, 0.197400798756287, 0.20197763879471,0.206632276416488, 0.211364783011207, 0.216175173135516, 0.221063403115838,0.226029369751421, 0.231072909127015, 0.236193795544475, 0.241391740582512,0.246666392293753, 0.785469324385707, 0.791248828037722, 0.796924291661326,0.802494739351842, 0.807959387559377, 0.813317637695433, 0.818569068441566,0.82371342784987, 0.828750625311994, 0.833680723461898, 0.838503930067752), model = c("mod1", "mod1", "mod1", "mod1", "mod1", "mod1","mod1", "mod1", "mod1", "mod1", "mod1", "mod1", "mod1", "mod1","mod1", "mod1", "mod1", "mod1", "mod1", "mod1", "mod1", "mod2","mod2", "mod2", "mod2", "mod2", "mod2", "mod2", "mod2", "mod2","mod2", "mod2", "mod2", "mod2", "mod2", "mod2", "mod2", "mod2","mod2", "mod2", "mod2", "mod2", "mod2")), .Names = c("dose","probability", "Lower", "Upper", "model"), row.names = c(1L,2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 90L, 91L, 92L, 93L, 94L,95L, 96L, 97L, 98L, 99L, 100L, 201L, 202L, 203L, 204L, 205L,206L, 207L, 208L, 209L, 210L, 211L, 290L, 291L, 292L, 293L, 294L,295L, 296L, 297L, 298L, 299L, 300L), class = "data.frame")

1 个答案:

答案 0 :(得分:3)

如果输出似乎仍然正确,警告通常不会让您感到不安。它们是警告而不是错误,因为它们只表示可能性出错了。

在这种情况下,似乎ggplot2的警告行为已发生变化。 geom_ribbon没有,仍然没有采用y美学 - 垂直轴只需yminymax。您正在使用y美学,这是未使用的,现在它让您知道它没有被使用。

要在没有警告的情况下获得相同的输出,我建议您从y = probability图层中删除geom_ribbon。 (您已经在情节初始化中指定了它。您甚至可以在x = dose图层中删除geom_ribbon以避免重复自己。)