- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在我的 ggplot
上绘制 abline
。
我可以使用以下方法绘制数据:
modl %>%
ggplot() +
geom_line(aes(x = date, y = logPrice), data = . %>% unnest(data))
但是,我在尝试通过数据绘制线性回归线时遇到了问题。
以下方法不起作用:
geom_abline(
slope = . %>% unnest(tidymodels) %>% filter(term == "date") %>% pull(estimate),
intercept = . %>% unnest(tidymodels) %>% filter(term == "(Intercept)") %>% pull(estimate)
)
数据如下:
# Groups: .id [1]
.id models tidymodels data
<chr> <list> <list> <list>
1 VRTX <lm> <tibble [2 × 5]> <tibble [100 × 8]>
编辑:
dat <- structure(list(.id = c("VRTX", "VRTX", "VRTX", "VRTX", "VRTX",
"VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX",
"VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX",
"VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX",
"VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX",
"VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX",
"VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX",
"VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX",
"VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX",
"VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX",
"VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX",
"VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX",
"VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX", "VRTX"), date = structure(c(17169,
17170, 17171, 17172, 17175, 17176, 17177, 17178, 17179, 17183,
17184, 17185, 17186, 17189, 17190, 17191, 17192, 17193, 17196,
17197, 17198, 17199, 17200, 17203, 17204, 17205, 17206, 17207,
17210, 17211, 17212, 17213, 17214, 17218, 17219, 17220, 17221,
17224, 17225, 17226, 17227, 17228, 17231, 17232, 17233, 17234,
17235, 17238, 17239, 17240, 17241, 17242, 17245, 17246, 17247,
17248, 17249, 17252, 17253, 17254, 17255, 17256, 17259, 17260,
17261, 17262, 17263, 17266, 17267, 17268, 17269, 17273, 17274,
17275, 17276, 17277, 17280, 17281, 17282, 17283, 17284, 17287,
17288, 17289, 17290, 17291, 17294, 17295, 17296, 17297, 17298,
17301, 17302, 17303, 17304, 17305, 17308, 17309, 17310, 17311
), class = "Date"), logPrice = c(4.31602035690836, 4.34445460070188,
4.3702070325713, 4.37437240314098, 4.4171524487178, 4.41799687846311,
4.40586522415372, 4.4114640581901, 4.42088668183346, 4.40121636585427,
4.41304065184823, 4.39333747525739, 4.39900669157719, 4.39937529757852,
4.40964177738779, 4.44488407953168, 4.44652611598691, 4.47015200864673,
4.43533037114274, 4.45283455962092, 4.45713408396959, 4.4626845492227,
4.46279987928647, 4.47072406655711, 4.46406729894837, 4.4741499349496,
4.49166545158536, 4.47903993153248, 4.4741499349496, 4.48762466712236,
4.49278508896161, 4.47392186517061, 4.4810798233994, 4.46072231628426,
4.45190246124124, 4.45120285768425, 4.45516091866138, 4.48751216501705,
4.50667497234427, 4.50324817411677, 4.4985866894606, 4.50191857835302,
4.50987005013333, 4.5143698216616, 4.52374318729236, 4.53870981928782,
4.54308202559635, 4.53206168189204, 4.52979985739765, 4.54934030102742,
4.52569399531349, 4.52091861178245, 4.51426028872484, 4.49423862528081,
4.50025402714471, 4.48919804342461, 4.49958745675377, 4.50865931864689,
4.49613624265995, 4.68222383394719, 4.67553545796919, 4.69455372883288,
4.67702559516856, 4.72108481948996, 4.73716290421006, 4.73847657080025,
4.7525551470123, 4.73672460819376, 4.73821398600866, 4.7437140041424,
4.73444254805427, 4.74327857068563, 4.74188402674831, 4.74170952395576,
4.76439370859218, 4.75960651358557, 4.76779914343257, 4.76447894289098,
4.75651690410063, 4.76575723360317, 4.7732237963436, 4.79264513289434,
4.77465977240762, 4.77954359813237, 4.75694661236208, 4.74353982042179,
4.74545371405291, 4.75900650498059, 4.74797096728123, 4.74805768220515,
4.74144778682863, 4.75557101246651, 4.77144701174072, 4.73952621225881,
4.77009122810188, 4.7708540762096, 4.77861918109365, 4.75866347263694,
4.76898829668438, 4.77575646970022)), row.names = c(NA, -100L
), groups = structure(list(.id = "VRTX", .rows = structure(list(
1:100), ptype = integer(0), class = c("vctrs_list_of", "vctrs_vctr"
))), row.names = 1L, class = c("tbl_df", "tbl", "data.frame"), .drop = TRUE), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"))
接下来我执行以下操作:
models <- dat %>%
group_by(.id) %>% # I have more than one ID in the full data.
nest() %>%
mutate(models = map(data, ~lm(logPrice ~ date, data = .x))) %>%
mutate(
tidymodels = map(models, ~tidy(.x)),
glancemodels = map(models, ~glance(.x)),
augmentmodels = map(models, ~augment(.x))
)
然后我可以运行ggplot
models %>%
ggplot() +
geom_line(aes(x = date, y = logPrice), data = . %>% unnest(data))
编辑:
这适用于单个观察(注意 - 它的斜率/截距与此处的示例不同)
models %>%
ggplot() +
geom_line(aes(x = date, y = logPrice), data = . %>% unnest(data)) +
geom_abline(
slope = 0.00036,
intercept = -2.4
)
我想使用整洁的方法更动态地执行此操作。
最佳答案
为什么不直接使用geom_smooth
来代替呢?您可以像往常一样按 .ID 进行分组,只需将其添加为美观或方面即可。
library(tidyverse)
ggplot(dat,aes(x = date, y = logPrice)) +
geom_line() +
geom_smooth(method = 'lm')
由reprex package于2020年2月23日创建(v0.3.0)
关于r - 嵌套整齐模型并在 ggplot 中绘制 abline,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60367000/
我学习 SDL 二维编程已有一段时间了,现在我想创建一个结合使用 SDL 和 OpenGL 的程序。我是这样设置的: SDL_Init(SDL_INIT_VIDEO); window = SDL_Cr
尝试查找可在地块中使用的不同类型项目的列表 来自不同样本的投影类型: projection = list(type = "equirectangular") projection = list(typ
我正在尝试使用 Java Graphics API 绘制 GIF,但无法使用下面的代码成功绘制 GIF。仅绘制 GIF 的第一张图像或缩略图,但不播放。 public void paintCompon
我目前正在使用 JFrame 并尝试绘制一个矩形,但我不知道如何执行代码 paint(Graphics g),如何获取 Graphics 对象? package com.raggaer.frame;
这个领域的新手,希望得到一些帮助。 我有一个"Missile.java" 类,我在那里画东西。我想绘制一个 ImageView,我正在使用以下代码: ImageView v = (ImageView)
下面列出了圆形的例子 这是我的 JavaScript 代码。 最佳答案 假设您的 randomColor 是正确的,您只需要: 从 canvas.onclick 中移除 context.clearR
我在绘制和缩放 ImageView 时遇到问题。请帮帮我.. 当我画一些东西然后拖动或缩放图像时 - 绘图保留在原处,如您在屏幕截图中所见。而且我只需要简单地在图片上绘图,并且可以缩放和拖动这张图片。
我们可以在形式之外绘制图像和文本...我的意思是在字面上... 我知道问这个问题很愚蠢但是我们能不能... 最佳答案 您可以通过创建表单并将其 TransparentColor 属性设置为背景色来“作
我在绘制/布局期间收到 3 个对象分配警告 super.onDraw(canvas); canvas.drawColor(Color.WHITE); Paint textPaint = new Pai
我有一个示例时间序列数据框: df = pd.DataFrame({'year':'1990','1991','1992','1993','1994','1995','1996',
我试图想出一种简洁的方法来绘制 R 数据框中所有列的 GridView 。问题是我的数据框中既有离散值又有数值。为简单起见,我们可以使用 R 提供的名为 iris 的示例数据集。我会使用 par(mf
我有一个由 10 列和 50 行组成的 data.frame。我使用 apply 函数逐列计算密度函数。现在我想绘制我一次计算的密度。 换句话说,而不是绘图... plot(den[[1]]) plo
我想知道我们如何才能在第一个和第二个组件之外绘制个人,如下所示: 最佳答案 这可能有效: pc.cr <- princomp(USArrests, cor = TRUE) pairs(pc.cr$lo
我是Pandas和matplotlib的新手,想绘制此DataFrame season won team matches pct_won 0 20
我正在尝试为 distplot 子图编写一个 for 循环。 我有一个包含许多不同长度列的数据框。 (不包括 NaN 值) fig = make_subplots( rows=len(asse
我想创建一个具有密度的 3d 图。 我使用函数 density 首先为特定的 x 值创建一个二维图,然后该函数创建密度并将它们放入 y 变量中。现在我有第二组 x 值并将其再次放入密度函数中,然后我得
全部, 我一直在研究全局所有 MTB 步道的索引。我是 Python 人,所以对于所有涉及的步骤,我都尝试使用 Python 模块。 我能够像这样从 OSM 立交桥 API 中获取关系: from O
我正在使用 e1071 包中的支持向量机对我的数据进行分类,并希望可视化机器实际如何进行分类。但是,在使用 plot.svm 函数时,出现无法解决的错误。 脚本: library("e1071") d
我制作了以下图表,它是使用 xts 对象创建的。 我使用的代码很简单 plot(graphTS1$CCLL, type = "l", las = 2, ylab = "(c)\nCC for I
在绘制状态图时,您如何知道哪些状态放在框中,哪些状态用于转换箭头?我注意到转换也是状态。 我正在查看 this page 上的图 1 : 最佳答案 转换不是状态。转换是将对象从一种状态移动到下一种状态
我是一名优秀的程序员,十分优秀!