首页 \ 问答 \ 使用ggplot2的交互图(interaction plot using ggplot2)

使用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)

enter image description here

I tried making the same model but holding wt at 2.2, but this model could not calculate the coefficient for wt:

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 word order and because you used $ the line must end with limits, 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 ...
  • 我认为非捕获(?:)会告诉它不要捕获单词标题 非捕获组 仍然使用文本 。 它们只是匹配 (文本被抓取并添加到匹配结果中),不捕获 (=在特定的编号或命名缓冲区中存储匹配值的一部分)。 要检查是否存在,只有外观(或锚点)。 很明显,你想要从匹配中丢弃前缀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<a ... </div> </div> </li> <li class="tw_li clearfix"> <div class="tw_li_con"> <div class="tw_li_title"> <h2><a href="/wenda/javascriptzzbdsfbhkhgk_325" target="_blank">javascript正则表达式非捕获比没有括号更快(javascript regex non-capture faster than no parenthesis at all)</a><i>[2022-10-16] </i></h2> </div> <div class="tw_li_cont"> 就V8而言,差异的原因与regexp文字只是普通字符串时出现的“优化”有关。 在这些情况下,进行简单的字符串搜索(例如,隐式的loremString.indexOf('laborum') ),如果regexp字符串中有任何特殊的正则表达式字符,则会跳过此行为更改。 所以/lab(?:o)rum/实际上正在通过regexp引擎和/laborum/隐式地通过indexOf()类搜索。 在使用--prof从节点分析代码,然后使用--prof-process命令行选项分析代码时,可以看到这一点。 As far as ... </div> </div> </li> <li class="tw_li clearfix"> <div class="tw_li_con"> <div class="tw_li_title"> <h2><a href="/wenda/feibuhuokuohaobuhuodanci_336" target="_blank">如何使用非捕获括号来捕获单词或根本没有?(How to use non-capturing parenthesis to capture a word or nothing at all?)</a><i>[2021-07-15] </i></h2> </div> <div class="tw_li_cont"> 你需要删除^和$元字符然后你正则表达式成为: order passes (?:quantity |)limits 因为当你使用^ ,行必须以单词order开头,因为你使用$行必须以limits结束,上面的正则表达式将匹配你输入字符串中任何位置的句子。 或使用以下正则表达式: ^Then order passes (?:quantity )?limits$ You need to remove the ^ and $ meta-characters then you regex becomes: orde ... </div> </div> </li> <li class="tw_li clearfix"> <div class="tw_li_con"> <div class="tw_li_title"> <h2><a href="/wenda/jcjavascriptzbhzzbdskhzhqnr_350" target="_blank">仅从Javascript中捕获正则表达式的括号中获取内容(Get only contents from capturing parenthesis of a Regular Expression in Javascript)</a><i>[2021-10-27] </i></h2> </div> <div class="tw_li_cont"> 如果你在你的正则表达式中使用一个捕获组(例如parens),那么就不能像你尝试这样做那样使用g标记获得多个匹配项,因为.match()函数不能返回两维数据(每次匹配时的捕获组列表)。 它本来可以设计用来做到这一点,但事实并非如此,为了得到这些信息,你必须多次循环并调用.exec() ,每次调用它时,每次连续匹配都会获得所有数据。 使用.exec()获取此数据如下所示: var str = "$1 $2 $3", matches; var allMatches = []; var reg = /\$(\d+) ... </div> </div> </li> <li class="tw_li clearfix"> <div class="tw_li_con"> <div class="tw_li_title"> <h2><a href="/wenda/buhuokuohaobuhuo_558" target="_blank">如何使用捕获括号捕获多次出现(How to capture multiple occurrence using capturing parenthesis)</a><i>[2022-11-05] </i></h2> </div> <div class="tw_li_cont"> 您错误地定位了圆括号和方括号,从而使捕获组成为字符类的一部分,从而阻止创建子匹配。 您需要交换括号的位置: /\[([a-z0-9]+)]/gi 请参阅下面的正则表达式演示和JS演示。 图案细节 : \[ - 文字[ ([a-z0-9]+) - 第1组捕获一个或多个字母数字 ] - 一个字面的结束括号(当它在字符类之外时不需要转义它) /gi - 全局和不区分大小写的匹配修饰符( [az]也将匹配AZ ,处理每个非重叠匹配) var re = /\[([a-z0-9]+)]/gi; var str = ... </div> </div> </li> <li class="tw_li clearfix"> <div class="tw_li_con"> <div class="tw_li_title"> <h2><a href="/wenda/feibuhuozubuhuo_573" target="_blank">为什么这个非捕获组会捕获?(Why does this non-capturing group capture?)</a><i>[2021-12-02] </i></h2> </div> <div class="tw_li_cont"> 捕获与匹配不同。 由于您在模式中指定了组合器,因此匹配器将拾取它们,无论它们是被捕获还是未捕获。 要捕获,您需要在字符串上exec()正则表达式并循环遍历结果,该结果将包含您的捕获组。 我还清理了你的模式并对其进行了修改,使其不会被不必要地捕获,并且会识别出一般的兄弟组合~ : var sel = "body.test ol+li ol > li #foobar p>span a[href=*]"; var re = /(?:^| |>|\+|~)+([a-z_-]+)/gi; var matches = ... </div> </div> </li> </ul> </div> <div class="main_right"> <div class="search-out"> <div class="search"> <form action="/wenda" target="_blank" method="get"> <input type="search" autocorrect="off" autocomplete="off" placeholder="请输入关键词" id="q" name="q" value=""> <button class="btn_s" type="submit">搜索</button> </form> </div> </div> <div class="commonh"> <h2>相关文章</h2> <span class="fr"><a href="/jiaocheng" target="_blank">更多</a></span> </div> <div class="right_list"> <li> <a title="JFreeChart 创建三维/3D饼图/条形图" href="/article/JFreeChart3Dbingtutiaoxingtu_11" target="_blank">JFreeChart 创建三维/3D饼图/条形图</a> </li> <li> <a title="JSP页面显示箭头线条交互图" href="/article/JSPymxsjtxtjht_5" target="_blank">JSP页面显示箭头线条交互图</a> </li> <li> <a title="JFreeChart笔记 (十) 时间序列图:差异对比图" href="/article/JFreeChartbjssjxltcydbt_0" target="_blank">JFreeChart笔记 (十) 时间序列图:差异对比图</a> </li> <li> <a title="JFreeChart 创建XY图XYLineChart" href="/article/JFreeChartXYtu_11" target="_blank">JFreeChart 创建XY图XYLineChart</a> </li> <li> <a title="JFreeChart创建线型图LineChart" href="/article/JFreeChartxianxingtu_11" target="_blank">JFreeChart创建线型图LineChart</a> </li> <li> <a title="JFreeChart创建条形图BarChart" href="/article/JFreeCharttiaoxingtu_11" target="_blank">JFreeChart创建条形图BarChart</a> </li> <li> <a title="jquery与servlet交互的json问题" href="/article/jqueryyuservletjiaohudejsonwenti_5" target="_blank">jquery与servlet交互的json问题</a> </li> <li> <a title="JFreeChart笔记 (四) 时间序列图:自动定位时间点" href="/article/JFreeChartbjssjxltzddwsjd_0" target="_blank">JFreeChart笔记 (四) 时间序列图:自动定位时间点</a> </li> <li> <a title="JFreeChart笔记 (七) 时间序列图:值标记线" href="/article/JFreeChartbjqsjxltzbjx_0" target="_blank">JFreeChart笔记 (七) 时间序列图:值标记线</a> </li> <li> <a title="JFreeChart笔记 (六) 时间序列图:移动平均线" href="/article/JFreeChartbjlsjxltydpjx_0" target="_blank">JFreeChart笔记 (六) 时间序列图:移动平均线</a> </li> </div> <div class="commonh"> <h2>最新问答</h2> <span class="fr"><a href="/wenda" target="_blank">更多</a></span> </div> <div class="right_list"> <li> <a title="您如何使用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?)" href="/wenda/gitdiffwjbjyyyyckfbfz_166" target="_blank">您如何使用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?)</a> </li> <li> <a title="将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)" href="/wenda/zfdzjqxsdfzdzfsz_208" target="_blank">将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)</a> </li> <li> <a title="OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)" href="/wenda/octobercmscebianlanchengxian_358" target="_blank">OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)</a> </li> <li> <a title="页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)" href="/wenda/ymjzdxzgljhs_380" target="_blank">页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)</a> </li> <li> <a title="codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)" href="/wenda/codeigniterzyybnayqgz_201" target="_blank">codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)</a> </li> <li> <a title="在计算机拍照在哪里进入" href="/wenda/jisuanjipaizhaozaina_8" target="_blank">在计算机拍照在哪里进入</a> </li> <li> <a title="使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)" href="/wenda/cingetczsrlzdqbxyzfdiscardunwant_470" target="_blank">使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)</a> </li> <li> <a title="No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)" href="/wenda/forxhjzforxhyx_517" target="_blank">No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)</a> </li> <li> <a title="单页应用程序:页面重新加载(Single Page Application: page reload)" href="/wenda/danyeyingyongchengxuyemianjiazai_103" target="_blank">单页应用程序:页面重新加载(Single Page Application: page reload)</a> </li> <li> <a title="在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)" href="/wenda/xunhuanzhongxuanmoshilieming_433" target="_blank">在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)</a> </li> <li> <a title="System.StackOverflow错误(System.StackOverflow error)" href="/wenda/systemstackoverflowcuowu_431" target="_blank">System.StackOverflow错误(System.StackOverflow error)</a> </li> <li> <a title="KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)" href="/wenda/knockoutjswzqtmbbeforeremoveafte_429" target="_blank">KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)</a> </li> <li> <a title="散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)" href="/wenda/sanliebaokuofangfaqiantaoshuxing_254" target="_blank">散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)</a> </li> <li> <a title="android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)" href="/wenda/androidsamsungrfswjxtycdj_556" target="_blank">android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)</a> </li> <li> <a title="TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)" href="/wenda/tensorflowsylbcjxz_538" target="_blank">TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)</a> </li> <li> <a title="企业安全培训的各项内容" href="/wenda/qiyeanquanpeixungexiangneirong_20" target="_blank">企业安全培训的各项内容</a> </li> <li> <a title="错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)" href="/wenda/cuowurpcshibai_88" target="_blank">错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)</a> </li> <li> <a title="C#类名中允许哪些字符?(What characters are allowed in C# class name?)" href="/wenda/cleimingzhongyunzifu_157" target="_blank">C#类名中允许哪些字符?(What characters are allowed in C# class name?)</a> </li> <li> <a title="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?)" href="/wenda/numpyint64zccnparrayzdtypefloat6_310" target="_blank">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?)</a> </li> <li> <a title="注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)" href="/wenda/zhuxiaoyinzangdaohangportlet_526" target="_blank">注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)</a> </li> <li> <a title="将多个行和可变行移动到列(moving multiple and variable rows to columns)" href="/wenda/duogexingkebianxingdongdaolie_442" target="_blank">将多个行和可变行移动到列(moving multiple and variable rows to columns)</a> </li> <li> <a title="提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)" href="/wenda/tjbdshljchrefbsjavascript_382" target="_blank">提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)</a> </li> <li> <a title="对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)" href="/wenda/setoninfowindowclicklisteneryitu_249" target="_blank">对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)</a> </li> <li> <a title="Angular $资源不会改变方法(Angular $resource doesn't change method)" href="/wenda/angularziyuanhuigaifangfa_275" target="_blank">Angular $资源不会改变方法(Angular $resource doesn't change method)</a> </li> <li> <a title="在Angular 5中不是一个函数(is not a function in Angular 5)" href="/wenda/angularzhonghanshu_308" target="_blank">在Angular 5中不是一个函数(is not a function in Angular 5)</a> </li> <li> <a title="如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)" href="/wenda/pzcompositec1mzmyzdtgfw_354" target="_blank">如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)</a> </li> <li> <a title="不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])" href="/wenda/bsxtxtsysfz_203" target="_blank">不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])</a> </li> <li> <a title="常见的python rpc和cli接口(Common python rpc and cli interface)" href="/wenda/changjianpythonrpcclijiekou_315" target="_blank">常见的python rpc和cli接口(Common python rpc and cli interface)</a> </li> <li> <a title="Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)" href="/wenda/mysqldbdgzdppdgzd_259" target="_blank">Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)</a> </li> <li> <a title="产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)" href="/wenda/chanpinyemianmagentochushouduiqi_417" target="_blank">产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)</a> </li> </div> </div> </div> </div> <div style="clear:both;"></div> <div class="footer"> <div class="mainbox"> <div class="info"> <p>Copyright ©2023 <a href="https://www.peixunduo.com" target="_blank">peixunduo.com</a> All Rights Reserved.<a href="https://beian.miit.gov.cn/" target="_blank">粤ICP备14003112号</a> </p> <p>本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!</p> </div> </div> </div> <script type="text/javascript" src="/resources/js/common.js?v=324"></script> <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https'){ bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else{ bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?9eebaceb5e4371a0aad59712a1a1ecff"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </body> </html>