小编Sop*_*ams的帖子

从图例中删除特定标记

对不起,如果这个问题已经得到回答,但我找不到我所追求的解决方案。我有一个同时使用geom_line和的情节geom_point。这样做的结果是,在图例中,当它们应该有一个或另一个时,它添加了一条线和一个点。我想保持圆圈的数据tg1tg2和移除行,然后做相反的数据full 保持线,但除去圆。我已经看到这样的事情在你想要从所有图例条目中删除点但没有做任何事情的地方只做细节从图例中删除 ggplot2 的 geom_point 图标。任何人都可以帮忙吗?谢谢。

阴谋

#剧情代码


library(ggplot2)
library(tidypaleo)

ggplot(LGRSL, aes(x =mmsl , y = Age))+
  coord_flip()+
  theme_classic(12)+
  geom_point(data=tg1,aes(x=mmslc,y=Year,col="Fort Denison 1"),pch=1,size=2)+
  geom_point(data=tg2,aes(x=mmslc,y=Year,col="Fort Denison 2"),pch=1,size=2)+
  geom_lineh(data = full, aes(x=Lutregalammslc,y=Year,col="Full budget"))+
  scale_colour_manual(values=c("grey15","grey50","black"))
  

## data

## tg1

structure(list(Year = 1886:1891, SLR = c(6919L, 6935L, 6923L, 
6955L, 6956L, 6957L), mmsl = c(-0.158, -0.142, -0.154, -0.122, 
-0.121, -0.12), m = c(6.919, 6.935, 6.923, 6.955, 6.956, 6.957
), GIA.correction = c(-0.02814, -0.02793, -0.02772, -0.02751, …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

2
推荐指数
1
解决办法
35
查看次数

错误:Aesthetics 必须是长度为 1 或与数据 (13) 相同:ymax

我正在尝试绘制一个图表,显示三种不同模型 wap、lg 和 reg 的物种优化和容差,但是我不断收到错误,Error: Aesthetics must be either length 1 or the same as the data (13): ymax我读到它与填充有关,但我确定我已经正确定义了填充?我还尝试保持所有三个模型共有的物种,以便数据框中没有任何 NA,但我遇到了同样的错误。任何人都可以解决这个问题吗?



specoptima<-read.csv("regspecopt.csv",header=TRUE)

ggplot()+
geom_point(data = specoptima, aes(x = Species, y = wapopt), color = "red",pch=21,size=3)+
geom_point(data = specoptima, aes(x = Species, y = lgopt), color = "blue",pch=23,size=3)+
geom_point(data = specoptima, aes(x = Species, y = regopt), color = "green",pch=23,size=3)+
  xlab('Species') +
  ylab('Height m AHD')+theme_classic()+
  geom_errorbar(aes(x=specoptima$Species,ymin=specoptima$wapopt-specoptima$waptol, ymax=specoptima$waopt+specoptima$waptol), width=0)+
  geom_errorbar(aes(x=specoptima$Species,ymin=specoptima$lgopt-specoptima$lgtol, ymax=specoptima$lgopt+spectopima$lgtol), width=0)+
  geom_errorbar(aes(x=specoptima$Species,ymin=specoptima$regopt-specoptima$regtol, ymax=specoptima$regopt+specoptima$regtol), width=0)

structure(list(Species = structure(c(13L, 12L, 4L, 9L, …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

0
推荐指数
1
解决办法
135
查看次数

使用 geom_line() 按正数或负数着色

抱歉,如果这是一个重复的问题,但我尝试过的其他答案并未产生我想要的情节。

我想根据该值是正值还是负值(我称之为“阶段”)对该图进行颜色编码。

当 geom_line() 达到 0 的上方或下方时,我希望它的颜色为“正”或“负” - 我认为以下方法可行,但似乎不起作用。有人能告诉我哪里出了问题吗?谢谢。

原剧情] 1

数据

structure(list(Date = c(1876, 1877, 1878, 1879, 1880, 1881), 
    value = c(4.95, -10.0416666666667, 2.95, 12.85, 7.8, -4.76666666666667
    ), phase = structure(c(3L, 1L, 3L, 3L, 3L, 1L), .Label = c("negative", 
    "neutral", "positive"), class = "factor")), row.names = c(NA, 
-6L), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x7ffb06817ce0>)
Run Code Online (Sandbox Code Playgroud)

代码

## create a column to determine if the phase is negative, positive or neutral i.e. 0

dd_avg$phase<-factor(sign(dd_avg$value), (-1):1, c('negative', 'neutral', 'positive'))
dd_avg …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

0
推荐指数
1
解决办法
1073
查看次数

标签 统计

ggplot2 ×3

r ×3