- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
输出(x)
structure(list(Host = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L), .Label = "A", class = "factor"), TimeStamp = structure(c(1L,
2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L), .Label = c("1/11/2013",
"1/12/2013", "1/13/2013", "1/14/2013", "1/15/2013"), class = "factor"),
Instance = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
2L), .Label = c("/application", "/db"), class = "factor"),
Free_Space = c(5048L, 5049L, 6000L, 4800L, 5100L, 317659L,
340000L, 350000L, 356666L, 370000L), Used_Space = c(3017L,
56000L, 60000L, 55000L, 54000L, 271657L, 150000L, 175000L,
165000L, 189999L), Total_Space = c(8064L, 61049L, 66000L,
59800L, 59100L, 589316L, 490000L, 525000L, 521666L, 559999L
)), .Names = c("Host", "TimeStamp", "Instance", "Free_Space",
"Used_Space", "Total_Space"), class = "data.frame", row.names = c(NA,
-10L))
我有这个数据框。我通过使用给定主机、时间戳和实例的 data.table 包添加 Free_Space 和 Used_Space 来驱动列名 Total_Space。
x<-data.table(x)
x<-x[,Total_Space:=Free_Space+Used_Space, by=c("Host", "Instance", "TimeStamp")]
我喜欢使用 ggplot2 中的 ggplot facet_wrap 来绘制以 GB 为单位的已用空间图,并通过 Total_Space 绘制一条 geom_line,以便用户可以看到有多少空间。
比如我这样做:
ggplot(x, aes(TimeStamp, Used_Space/1024, group=Instance)) + geom_area(fill="blue") + geom_smooth(method="lm", colour="orange",se=T, size=1) + geom_hline(data=x, aes(yintercept = Total_Space/1024), col="red")+ facet_wrap(~Host+Instance, ncol=3, scales="free")
我看到的问题是,由于 Total_Space 正在变化,我为同一个实例和主机获得了多个 geom_hline。
我的问题是,如何在为每个实例和主机执行 geom_hline 时选择最新的时间戳?我需要在 geom_hline 中显示最新的 Total_Space。
我试过这种方法:
x<-x[,LatestTS:=tail(p[order(p$TimeStamp),],1)$Total_Space, by=c("Host", "Instance", "TimeStamp")]
没用。它为所有实例选择相同的数字。
最佳答案
我的解决方案是,首先,使您的列 TimeStamp
成为日期
x$TimeStamp<-as.Date(x$TimeStamp,format="%m/%d/%Y")
然后,由于您的数据对象是data.table
,您可以根据Host
和Instance
对数据进行子集化,并设置TimeStamp
应该是最大值。
x[,.SD[TimeStamp==max(TimeStamp)],by="Host,Instance"]
Host Instance TimeStamp Free_Space Used_Space Total_Space
1: A /application 2013-01-15 5100 54000 59100
2: A /db 2013-01-15 370000 189999 559999
现在您可以在 geom_hline()
中使用这一行。使用 scale_x_date()
,您现在将获得更多控制此比例的可能性。
library(scales)
ggplot(x, aes(TimeStamp, Used_Space/1024, group=Instance)) +
geom_area(fill="blue") + geom_smooth(method="lm", colour="orange",se=T, size=1) +
geom_hline(data=x[,.SD[TimeStamp==max(TimeStamp)],by="Host,Instance"], aes(yintercept = Total_Space/1024), col="red")+
facet_wrap(~Host+Instance, ncol=3, scales="free") +
scale_x_date(labels = date_format("%m/%d/%Y"))
关于r - 在 ggplot2 中执行 geom_hline 时选择最新的数据集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15417420/
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
ECharts是一个纯Javascript的图表库,可以流畅的运行在PC和移动设备上,兼容当前绝大部分浏览器,底层依赖轻量级的Canvas类库ZRender,提供直观、生动、可交互、可高度个性化定制
前言 提示:这里可以添加本文要记录的大概内容: 例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。 提示:以下是本篇文章正文
作为一名ios开发攻城狮,在苹果没有出arc(自动内存管理机制)时,我们几乎有一半的开发时间都耗费在这么管理内存上.后来苹果很人性的出了arc,虽然在很大程度上,帮助我们开发者节省了精力和时间.但是
如何反转Pandas中DataSeries的排序顺序,以便我按降序使用它们? 最佳答案 In [28]: s = pd.Series([20, 10, 30], ['c', 'a', 'b']) In
这个问题已经有答案了: 已关闭10 年前。 Possible Duplicate: Is jQuery $.browser Deprecated? 最新的 jQuery 库是否发生变化 $.brows
我正在开发一个 Intranet 项目,所以我无法复制/粘贴代码,所以希望我的描述和一些小片段会有所帮助。 我知道 MySQL 触发器无法做到这一点,但希望有一种干净的 JPA PrePersist(
这是数据集: 人员状态日期 埃里克 1 1/1/2015 埃里克 2 2/1/2015 埃里克 3 2015 年 3 月 1 日 约翰福音 1 3/1/2015 约翰福音 2 2015 年 2 月 1
现在我正在使用下面的查询按每篇文章的 auto_increment id 排序 mysql_query("SELECT * FROM articles ORDER BY id DESC"); 我想知道
已结束。此问题不符合 Stack Overflow guidelines .它目前不接受答案。 我们不允许提出有关书籍、工具、软件库等方面的建议的问题。您可以编辑问题,以便用事实和引用来回答它。 关闭
已结束。此问题不符合 Stack Overflow guidelines .它目前不接受答案。 我们不允许提出有关书籍、工具、软件库等方面的建议的问题。您可以编辑问题,以便用事实和引用来回答它。 关闭
现在我正在使用下面的查询按每篇文章的 auto_increment id 排序 mysql_query("SELECT * FROM articles ORDER BY id DESC"); 我想知道
在我们做文章的时候常用一些函数修改来实现自己的页面效果,例如,时间的自定义格式 我们常常需要乃至的,搜集了些有关时间格式的CODE,作大家为参考,希望对大家有些帮助 列表页list_article
我想将某些东西提交到 github 存储库,但我(显然)没有任何权利这样做。我对那个 repo 做了一个分支,提交了我的更改并提交了一个 pull-request。 现在,问题是过了一段时间其他人已经
我是 SQL 新手,所以现有的答案对我来说有点复杂。 我有三张 table : WORKER |id |name |date |... JOB |id |name |salary |accept AP
我正在自动从PowerPoint和Excel电子表格中生成PowerPoint报表。在粘贴表格之前,我已经完成了整个过程。 我使用PPApp.CommandBars.ExecuteMso ("Past
我们有 1 个 Kafka 主题和 1 个分区: 从 spring boot kafka 消费者那里看到一个相当奇怪的行为。 Spring kafka消费者在重新启动时总是从主题的开头开始消费。 我已
通过编程从iOS照片库获取最新照片是否有技巧? 我知道我可以按日期搜索,但是我必须每隔一微秒进行一次扫描,以便进行某种比较以准确地找到它。 有没有人做过这个或任何想法? 最佳答案 我之前采取的一种方法
我们上周将 Web 应用程序中的 Telerik Kendo 库从 V2015.2.902 升级到 V2016.1.112。从那时起,我们注意到使用 Kendo 的页面需要很长时间才能加载(30 秒到
我有两个表: STUDENT GRADES ---------- ---------- id id name person_id ad
我是一名优秀的程序员,十分优秀!