- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想用ggplot2建立一个情节。因此,我使用geom_line来可视化线,并使用geom_smooth来显示特定索引的最小-最大范围。
使用了两个数据框,第一行包含日期(例如:2013-02-04),下一行是测量值(例如2.532283)。
首先,我生成一个具有所有样式的空ggplot:
yrange_EVI2 =是索引范围(最小-最大)
xrange =是x轴的日期范围(最早-最新日期)
EVI2_veg <- ggplot() + geom_blank() +
ylim(yrange_EVI2) + xlim(xrange) +
ggtitle("EVI2 for reference-data in Azraq (Jordan)") + ylab("EVI2") + xlab("month") +
theme_bw(base_size = 12, base_family = "Times New Roman")
EVI2_veg <- EVI2_veg +
geom_smooth(aes(x=Date, y=Vegetable_mean, ymin=Vegetable_min, ymax=Vegetable_max), data=Grouped_Croptypes_EVI2, stat="identity") +
geom_line(aes(x=Date, y=Tomato), data=Sample_EVI2_A_SPOT)
EVI2_veg <- EVI2_veg +
scale_fill_manual("Min-Max-Range and Mean \nof specific Croptypes",labels=c("Vegetable","Tomato"),values=c("#008B00","#FFFFFF")) +
scale_color_manual("Min-Max-Range and Mean \nof specific Croptypes",labels=c("Vegetable","Tomato"),values=c("#008B00","#CD4F39"))
最佳答案
首先,将示例数据包含在任何绘图代码中总是很不错的,否则我们将无法运行它来查看您所看到的内容。在发表其他文章之前,请先阅读how to make a great R reproducible example。这将使人们更轻松地为您提供帮助。无论如何,这是一些示例数据
Sample_EVI2_A_SPOT<-data.frame(
Date=seq(as.Date("2014-01-01"), as.Date("2014-02-01"), by="1 day"),
Tomato = cumsum(rnorm(32))
)
Grouped_Croptypes_EVI2<-data.frame(
Date=seq(as.Date("2014-01-01"), as.Date("2014-02-01"), by="1 day"),
Vegetable_mean=cumsum(rnorm(32))
)
Grouped_Croptypes_EVI2<-transform(Grouped_Croptypes_EVI2,
Vegetable_max=Vegetable_mean+runif(32)*5,
Vegetable_min=Vegetable_mean-runif(32)*5
)
EVI2_veg <- ggplot() + geom_blank() +
ggtitle("EVI2 for reference-data in Azraq (Jordan)") +
ylab("EVI2") + xlab("month") +
theme_bw(base_size = 12, base_family = "Times New Roman") +
geom_smooth(aes(x=Date, y=Vegetable_mean, ymin=Vegetable_min,
ymax=Vegetable_max, color="Vegetable", fill="Vegetable"),
data=Grouped_Croptypes_EVI2, stat="identity") +
geom_line(aes(x=Date, y=Tomato, color="Tomato"), data=Sample_EVI2_A_SPOT) +
scale_fill_manual(name="Min-Max-Range and Mean \nof specific Croptypes",
values=c(Vegetable="#008B00", Tomato="#FFFFFF")) +
scale_color_manual(name="Min-Max-Range and Mean \nof specific Croptypes",
values=c(Vegetable="#008B00",Tomato="#CD4F39"))
EVI2_veg
color=
调用中添加了
fill=
和
aes()
。您确实应该将所需的内容放在
aes()
的图例中。在这里,我指定“假”颜色,然后在
scale_*_manual
命令中对其进行定义。
关于r - 如何为ggplot2添加手动颜色(geom_smooth/geom_line),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24063163/
出于某种原因,在我的图表中,geom_smooth 线的颜色与阴影区域不同。我不确定是什么原因造成的。例如,蓝色阴影的 Retired 有一条绿线,而绿色阴影的 Unsigned 有一条蓝线。事件状态
我有以下 ggplot2 代码,可以绘制不同阶数的多个多项式拟合: library(ggplot2) set.seed(1234) n = 400 x = rnorm(n, sd=0.4) y = -
如何制作 ggplot 图 geom_smooth(method="lm"),但前提是它符合某些标准?例如,如果我只想在斜率具有统计显着性的情况下画线(即 lm 拟合中的 p 小于 0.01)。 编辑
我在 R 中计算了二项式回归: Call: glm(formula = cbind(success, failure) ~ x * f, family = "binomial", data =
这是一些数据和情节: set.seed(18) data = data.frame(y=c(rep(0:1,3),rnorm(18,mean=0.5,sd=0.1)),colour=rep(1:2,1
我正在使用 ggplot2 中的 geom_smooth()。 在 Hadley Wickham 的书(“ggplot2 - Elegant Graphics for Data Analysis”)中
您可以非常轻松地在 ggplot2 中扩展回归线: c =init_range[1]] ggplot2:::predictdf.default(model, xseq[-length(xseq
在查看this时问题,我无法为 geom_smooth 指定自定义线性模型。我的代码如下: example.label <- c("A","A","A","A","A","B","B","B","B"
我正在努力使用 geom_smooth 来创建几何平滑线。下面我报告代码: library(ggplot2) #DATAFRAME RawData <- data.frame("Time" = c(0
是否可以让geom_smooth产生单调递减函数? 第一个例子看起来是单调递减的: library(tidyverse) df <- structure(list(x = c(-55, 11, 19,
这个问题在这里已经有了答案: ggplot - Add regression line on a boxplot with binned (non-continuous) x-axis (1 个回答)
我正在绘制一些数据并具有以下代码: ggplot(aes(x = x, y = y), data = data) + geom_point(alpha = 1/15, color = 'blue'
我想用ggplot2建立一个情节。因此,我使用geom_line来可视化线,并使用geom_smooth来显示特定索引的最小-最大范围。 使用了两个数据框,第一行包含日期(例如:2013-02-04)
如果我添加 geom_smooth,那么我会在 shape 图例中得到不同颜色的矩形,而不是黑色圆圈。我怎样才能防止这种情况发生?这是 sample code . library(ggplot2) d
我正在寻找两个变量之间的比较图,重叠两个产品的 geom_smooth()。测量力理论的起点是 (x=0; y=0) 但是当我制作图表时,蓝色回归线是用 geom_smooth() 不传递坐标 (0;
如何在 geom_smooth() 中改变线条边框的颜色? library(ggplot2) mtcars$cyl <- as.factor(mtcars$cyl) ggplot(mtcars, ae
我有如下数据: library(quantreg) library(ggplot2) data <- structure(list(country_mean_rep = structure(c(73.
这个问题在这里已经有了答案: R stat_smooth all points (1 个回答) 关闭4年前。 我正在绘制一个包含 3 个不同类别的图表,这些类别由不同的颜色表示。我想要一条曲线来表示总
我有一个小问题,我自己无法解决这个问题。 我有一个简单的数据框,我想用 ggplot2 绘制它.当我使用变量 重量 作为一个因素,我得到 x 轴上的所有值,s。 plot 2,但当我将它用作整数时,s
使用以下代码: library(ggplot2) ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point(aes(colour=factor(cyl)))
我是一名优秀的程序员,十分优秀!