{"id":6682,"date":"2022-08-07T17:37:05","date_gmt":"2022-08-07T17:37:05","guid":{"rendered":"https:\/\/www.garysieling.com\/blog\/?p=6682"},"modified":"2022-08-07T18:20:51","modified_gmt":"2022-08-07T18:20:51","slug":"plotting-cpu-over-time-with-r","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/plotting-cpu-over-time-with-r\/","title":{"rendered":"R: Plotting CPU% over time"},"content":{"rendered":"\n<p>Given a dataframe (df) containing CPU measurements over time:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"> cpu memory_timepoint  max_memory net_io_timeout max_net_io block_io_timepoint max_block_io index<\/pre>\n\n\n\n<p><br>1 0.686 27965522. 6067715047. 0 0 0 0 1<br>2 0.0025 27965522. 6067715047. 0 0 0 0 2<br>3 0.003 27797750. 6067715047. 0 0 0 0 3<\/p>\n\n\n\n<p>This code will make a simple chart:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>library('ggplot2')\nlibrary('scales')\n\nggplot(df, aes(x=index, y=cpu)) + \n  geom_point(aes()) + \n     labs(\n       subtitle=\"Container Tracking\", \n       y=\"CPU\", \n       x=\"Timepoint\", \n       title=\"CPU over time\", \n       caption = \"Source: docker stats\") + \n  scale_y_continuous(labels = scales::percent) + \n  scale_x_continuous(breaks = pretty_breaks(n=max(df$index))) <\/code><\/pre>\n\n\n\n<p>Save the plot:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ggsave(\"~\/Desktop\/cpu.png\", last_plot())<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"715\" height=\"1030\" src=\"https:\/\/www.garysieling.com\/blog\/wp-content\/uploads\/2022\/08\/cpu-715x1030.png\" alt=\"\" class=\"wp-image-6684\" srcset=\"https:\/\/www.garysieling.com\/blog\/wp-content\/uploads\/2022\/08\/cpu-715x1030.png 715w, https:\/\/www.garysieling.com\/blog\/wp-content\/uploads\/2022\/08\/cpu-208x300.png 208w, https:\/\/www.garysieling.com\/blog\/wp-content\/uploads\/2022\/08\/cpu-768x1106.png 768w, https:\/\/www.garysieling.com\/blog\/wp-content\/uploads\/2022\/08\/cpu-1067x1536.png 1067w, https:\/\/www.garysieling.com\/blog\/wp-content\/uploads\/2022\/08\/cpu-1422x2048.png 1422w, https:\/\/www.garysieling.com\/blog\/wp-content\/uploads\/2022\/08\/cpu.png 1441w\" sizes=\"(max-width: 715px) 100vw, 715px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Given a dataframe (df) containing CPU measurements over time: 1 0.686 27965522. 6067715047. 0 0 0 0 12 0.0025 27965522. 6067715047. 0 0 0 0 23 0.003 27797750. 6067715047. 0 0 0 0 3 This code will make a simple chart: Save the plot:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[6,8],"tags":[450],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/6682"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=6682"}],"version-history":[{"count":3,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/6682\/revisions"}],"predecessor-version":[{"id":6690,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/6682\/revisions\/6690"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=6682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=6682"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=6682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}