使用ggplot2的交互图(interaction plot using ggplot2)
以下代码显示了使用
effects
库的交互图:model <- lm(mpg ~ hp + wt + hp:wt, data=mtcars) library(effects) plot(effect("hp:wt", model, list(wt=c(2.2,3.2,4.2))), multiline=TRUE)
我尝试制作相同的模型,但保持
wt
为2.2,但这个模型无法计算wt
的系数:mtcars$wt_2.2 <- 2.2 model2.2 <- lm(mpg ~ hp + wt_2.2 + hp:wt, data=mtcars) coef(model2.2)
如何使用ggplot2制作相同的图?
The following code shows an interaction plot using the
effects
library:model <- lm(mpg ~ hp + wt + hp:wt, data=mtcars) library(effects) plot(effect("hp:wt", model, list(wt=c(2.2,3.2,4.2))), multiline=TRUE)
I tried making the same model but holding
wt
at 2.2, but this model could not calculate the coefficient forwt
:mtcars$wt_2.2 <- 2.2 model2.2 <- lm(mpg ~ hp + wt_2.2 + hp:wt, data=mtcars) coef(model2.2)
How can I make the same plot using ggplot2?
原文:https://stackoverflow.com/questions/19971972
更新时间:2023-11-26 17:11
最满意答案
你需要删除
^
和$
元字符然后你正则表达式成为:order passes (?:quantity |)limits
因为当你使用
^
,行必须以单词order
开头,因为你使用$
行必须以limits
结束,上面的正则表达式将匹配你输入字符串中任何位置的句子。或使用以下正则表达式:
^Then order passes (?:quantity )?limits$
You need to remove the
^
and$
meta-characters then you regex becomes:order passes (?:quantity |)limits
because when you use
^
the line must start with the wordorder
and because you used$
the line must end withlimits
, the above regex will match your sentence anywhere inside the input string.or use the following regex:
^Then order passes (?:quantity )?limits$
相关问答
更多-
我想检查在我的时间戳之前和之后是否存在非数字字符。 非数字字符不需要存在,但不应该在之前或之后直接存在数字字符。 我不想捕获这个非数字字符。 匹配此类时间戳的最佳方法是使用外观 : (?您无法使用扫描仪进行解析。 你需要一个解析器。 正则表达式无法处理嵌套括号。 它们是完成此任务的错误技术。 You can't parse with a scanner. You need a parser. Regular expressions cannot handle nested parentheses. They are the wrong technology for this task.你想要一个积极的前瞻: \d+(?=:$) 非捕获组只是一个无法通过反向引用访问的组; 尽管如此,他们仍然是比赛的一部分。 或者,您可以使用 (\d+):$ 并获得第一场比赛组。 You want a positive lookahead: \d+(?=:$) A non-capturing group is simply a group that cannot be accessed via a backreference; they still are part of the match, non ...
正则表达式总是贪婪,即使我给它非捕获括号?(Regex is always greedy, even when I give it non-capturing parentheses?)[2023-09-25]
我认为非捕获(?:)会告诉它不要捕获单词标题 非捕获组 仍然使用文本 。 它们只是匹配 (文本被抓取并添加到匹配结果中),不捕获 (=在特定的编号或命名缓冲区中存储匹配值的一部分)。 要检查是否存在,只有外观(或锚点)。 很明显,你想要从匹配中丢弃前缀title : 你不能使用lookbehind,因为在Python re模块中不允许使用可变宽度的 lookbehind(里面有量词的那个)。 通常的解决方法是围绕您需要获取的模式使用捕获组 。 您可以在[\w\s]+子模式周围设置捕获组,以将该值捕获到组1中 ...就像是: ^(?P.+?(?=\s-\s)) # artist with pos. lookahead \s-\s # space - space (?P .+?(?=(?:\(?Feat\.)|$)) # title with pos. lookahead \(? # optional open parenthesis (?P javascript正则表达式非捕获比没有括号更快(javascript regex non-capture faster than no parenthesis at all)[2022-10-16]
就V8而言,差异的原因与regexp文字只是普通字符串时出现的“优化”有关。 在这些情况下,进行简单的字符串搜索(例如,隐式的loremString.indexOf('laborum') ),如果regexp字符串中有任何特殊的正则表达式字符,则会跳过此行为更改。 所以/lab(?:o)rum/实际上正在通过regexp引擎和/laborum/隐式地通过indexOf()类搜索。 在使用--prof从节点分析代码,然后使用--prof-process命令行选项分析代码时,可以看到这一点。 As far as ...如何使用非捕获括号来捕获单词或根本没有?(How to use non-capturing parenthesis to capture a word or nothing at all?)[2021-07-15]
你需要删除^和$元字符然后你正则表达式成为: order passes (?:quantity |)limits 因为当你使用^ ,行必须以单词order开头,因为你使用$行必须以limits结束,上面的正则表达式将匹配你输入字符串中任何位置的句子。 或使用以下正则表达式: ^Then order passes (?:quantity )?limits$ You need to remove the ^ and $ meta-characters then you regex becomes: orde ...如果你在你的正则表达式中使用一个捕获组(例如parens),那么就不能像你尝试这样做那样使用g标记获得多个匹配项,因为.match()函数不能返回两维数据(每次匹配时的捕获组列表)。 它本来可以设计用来做到这一点,但事实并非如此,为了得到这些信息,你必须多次循环并调用.exec() ,每次调用它时,每次连续匹配都会获得所有数据。 使用.exec()获取此数据如下所示: var str = "$1 $2 $3", matches; var allMatches = []; var reg = /\$(\d+) ...您错误地定位了圆括号和方括号,从而使捕获组成为字符类的一部分,从而阻止创建子匹配。 您需要交换括号的位置: /\[([a-z0-9]+)]/gi 请参阅下面的正则表达式演示和JS演示。 图案细节 : \[ - 文字[ ([a-z0-9]+) - 第1组捕获一个或多个字母数字 ] - 一个字面的结束括号(当它在字符类之外时不需要转义它) /gi - 全局和不区分大小写的匹配修饰符( [az]也将匹配AZ ,处理每个非重叠匹配) var re = /\[([a-z0-9]+)]/gi; var str = ...捕获与匹配不同。 由于您在模式中指定了组合器,因此匹配器将拾取它们,无论它们是被捕获还是未捕获。 要捕获,您需要在字符串上exec()正则表达式并循环遍历结果,该结果将包含您的捕获组。 我还清理了你的模式并对其进行了修改,使其不会被不必要地捕获,并且会识别出一般的兄弟组合~ : var sel = "body.test ol+li ol > li #foobar p>span a[href=*]"; var re = /(?:^| |>|\+|~)+([a-z_-]+)/gi; var matches = ...相关文章
更多- JFreeChart 创建三维/3D饼图/条形图
- JSP页面显示箭头线条交互图
- JFreeChart笔记 (十) 时间序列图:差异对比图
- JFreeChart 创建XY图XYLineChart
- JFreeChart创建线型图LineChart
- JFreeChart创建条形图BarChart
- jquery与servlet交互的json问题
- JFreeChart笔记 (四) 时间序列图:自动定位时间点
- JFreeChart笔记 (七) 时间序列图:值标记线
- JFreeChart笔记 (六) 时间序列图:移动平均线
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)