{"id":3387,"date":"2024-03-08T12:07:22","date_gmt":"2024-03-08T03:07:22","guid":{"rendered":"https:\/\/plaza.umin.ac.jp\/~OIO\/?p=3387"},"modified":"2024-03-24T15:14:03","modified_gmt":"2024-03-24T06:14:03","slug":"r-ggplot-%e3%81%a7%e8%a4%87%e6%95%b0%e3%81%ae%e3%83%87%e3%83%bc%e3%82%bf%e3%83%95%e3%83%ac%e3%83%bc%e3%83%a0%e3%82%92%e7%b5%90%e5%90%88%e3%81%97%e3%81%a6%e6%8f%8f%e7%94%bb","status":"publish","type":"post","link":"https:\/\/plaza.umin.ac.jp\/~OIO\/?p=3387","title":{"rendered":"R ggplot \u3067\u8907\u6570\u306e\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u3092\u7d50\u5408\u3057\u3066\u63cf\u753b"},"content":{"rendered":"<h1>\u306f\u3058\u3081\u306b<\/h1>\n<p>\u3053\u3093\u306a\u611f\u3058\u306e\u30c7\u30fc\u30bf\u304c\u3042\u308a\u307e\u3057\u305f<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/plaza.umin.ac.jp\/~OIO\/wp-content\/uploads\/2024\/03\/66c19942ab4ba346fdb64ccc04cde373-3.png\" alt=\"\" width=\"392\" height=\"287\" class=\"aligncenter size-full wp-image-3392\" srcset=\"https:\/\/plaza.umin.ac.jp\/~OIO\/wp-content\/uploads\/2024\/03\/66c19942ab4ba346fdb64ccc04cde373-3.png 392w, https:\/\/plaza.umin.ac.jp\/~OIO\/wp-content\/uploads\/2024\/03\/66c19942ab4ba346fdb64ccc04cde373-3-300x220.png 300w, https:\/\/plaza.umin.ac.jp\/~OIO\/wp-content\/uploads\/2024\/03\/66c19942ab4ba346fdb64ccc04cde373-3-150x110.png 150w, https:\/\/plaza.umin.ac.jp\/~OIO\/wp-content\/uploads\/2024\/03\/66c19942ab4ba346fdb64ccc04cde373-3-80x60.png 80w\" sizes=\"auto, (max-width: 392px) 100vw, 392px\" \/><\/p>\n<p>x\u306f\u6642\u671f\u3000as.Date(&#8220;2024-03-08&#8221;)\u3068\u304b\u306e\u5024\u304c\u5165\u3063\u3066\u3044\u308b\u30d9\u30af\u30bf\u30fc<\/p>\n<p>cancer \u306fc(&#8220;GC&#8221;, &#8220;BC&#8221;) \u304c\u3093\u7a2e\u306e\u5024\u304c\u5165\u3063\u305f\u30d9\u30af\u30bf\u30fc<\/p>\n<p>y \u306f\u8868\u793a\u3057\u305f\u3044\u5024\uff08\u5e73\u5747\u5024\u3068\u304b\u983b\u5ea6\u3068\u304b\uff09<\/p>\n<p>low\/hight \u306f\u30a8\u30e9\u30fc\u30d0\u30fc\u306e\u4e0a\u9650\u30fb\u4e0b\u9650\uff0895%\u4fe1\u983c\u533a\u9593\u3068\u304b\uff09<\/p>\n<h1>\u4f55\u304c\u3057\u305f\u3044\u306e\u304b<\/h1>\n<p>\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u3092\u304c\u3093\u7a2e\u5225\u306b\u4f5c\u6210\u3057\u305f\u5f8c\u306b\u3001\u305d\u308c\u3089\u3092\u4e00\u3064\u306e\u30b0\u30e9\u30d5\u3067\u8868\u793a\u3057\u305f\u304f\u306a\u3063\u305f<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">library(ggplot2)\r\nlibrary(ggsci)\r\nlibrary(scales)\r\n\r\nBC_data_frame &lt;- data.frame(x, cancer, y, low, high) # BC\u3068GC\u3067\u305d\u308c\u305e\u308c\u306e\u30d9\u30af\u30bf\u30fc\u306b\u306f\r\nGC_data_frame &lt;- data.frame(x, cancer, y, low, high) # \u7570\u306a\u308b\u5024\u304c\u5165\u3063\u3066\u3044\u308b\r\n\r\ncombined_data_frame &lt;- <span style=\"color: #0000ff;\">rbind<\/span>(BC_data_frame, GC_data_frame)\r\n\r\ng5 &lt;- ggplot(combined_data_frame, aes(x, y, color = cancer)) + \r\n   geom_smooth(aes(ymin = low, ymax = high), alpha = 0.2) + \r\n   scale_color_nejm() + \r\n   geom_point() + \r\n   geom_errorbar(aes(ymin = low, ymax = high), width = 10) + \r\n   scale_x_date(limits = c(as.Date(\"2020-05-15\"), as.Date(\"2024-01-31\")), oob = oob_keep) +\r\n   scale_y_continuous(limits = c(0, 0.2), oob = oob_keep)\r\nplot(g5)\r\n\u3069<\/pre>\n<h1>\u3069\u3046\u3057\u305f\u3089\u3069\u3046\u306a\u3063\u305f<\/h1>\n<p>rbind\u3067\u7d50\u5408\u3057\u3066\u3001\u305d\u306e\u307e\u307e\u30d7\u30ed\u30c3\u30c8\u3057\u305f\u30892\u7cfb\u5217\u304c\u5206\u304b\u308c\u3066\u8868\u793a\u3055\u308c\u305f<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/plaza.umin.ac.jp\/~OIO\/wp-content\/uploads\/2024\/03\/Rplot-1.png\" alt=\"\" width=\"882\" height=\"531\" class=\"aligncenter size-full wp-image-3388\" srcset=\"https:\/\/plaza.umin.ac.jp\/~OIO\/wp-content\/uploads\/2024\/03\/Rplot-1.png 882w, https:\/\/plaza.umin.ac.jp\/~OIO\/wp-content\/uploads\/2024\/03\/Rplot-1-300x181.png 300w, https:\/\/plaza.umin.ac.jp\/~OIO\/wp-content\/uploads\/2024\/03\/Rplot-1-700x421.png 700w, https:\/\/plaza.umin.ac.jp\/~OIO\/wp-content\/uploads\/2024\/03\/Rplot-1-150x90.png 150w, https:\/\/plaza.umin.ac.jp\/~OIO\/wp-content\/uploads\/2024\/03\/Rplot-1-768x462.png 768w, https:\/\/plaza.umin.ac.jp\/~OIO\/wp-content\/uploads\/2024\/03\/Rplot-1-500x301.png 500w, https:\/\/plaza.umin.ac.jp\/~OIO\/wp-content\/uploads\/2024\/03\/Rplot-1-800x482.png 800w\" sizes=\"auto, (max-width: 882px) 100vw, 882px\" \/><\/p>\n<p>\u5168\u4f53\u306f\u3053\u3093\u306a\u611f\u3058<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">setwd(\"C:\/Users\/****\")\r\n\r\nlibrary(ggplot2)\r\nlibrary(ggsci)\r\nlibrary(scales)\r\n\r\nx &lt;- seq(as.Date(\"2020-06-01\"), as.Date(\"2024-01-01\"), by = \"month\")\r\nk1 &lt;-  binom.test(1, 11);\ty &lt;- c(k1$estimate);\tlow &lt;- c(k1$conf.int[1]);\thigh &lt;- c(k1$conf.int[2])\r\nk2 &lt;-  binom.test(1, 19);\ty &lt;- c(y, k2$estimate);\tlow &lt;- c(low, k2$conf.int[1]);\thigh &lt;- c(high, k2$conf.int[2])\r\n# ... \u30c7\u30fc\u30bf\u500b\u6240\u306f\u4e2d\u7565\r\nk43 &lt;- binom.test(12, 135);\ty &lt;- c(y, k43$estimate);\tlow &lt;- c(low, k43$conf.int[1]);\thigh &lt;- c(high, k43$conf.int[2])\r\nk44 &lt;- binom.test(11, 131);\ty &lt;- c(y, k44$estimate);\tlow &lt;- c(low, k44$conf.int[1]);\thigh &lt;- c(high, k44$conf.int[2])\r\ncancer &lt;- rep(\"GC\", 44)\r\nGC_data_frame &lt;- data.frame(x, cancer, y, low, high)\r\n\r\nk1 &lt;-  binom.test(0, 12);\ty &lt;- c(k1$estimate);\tlow &lt;- c(k1$conf.int[1]);\thigh &lt;- c(k1$conf.int[2])\r\nk2 &lt;-  binom.test(0, 118);\ty &lt;- c(y, k2$estimate);\tlow &lt;- c(low, k2$conf.int[1]);\thigh &lt;- c(high, k2$conf.int[2])\r\n# ... \u30c7\u30fc\u30bf\u500b\u6240\u306f\u4e2d\u7565\r\nk43 &lt;- binom.test(2, 302);\ty &lt;- c(y, k43$estimate);\tlow &lt;- c(low, k43$conf.int[1]);\thigh &lt;- c(high, k43$conf.int[2])\r\nk44 &lt;- binom.test(3, 279);\ty &lt;- c(y, k44$estimate);\tlow &lt;- c(low, k44$conf.int[1]);\thigh &lt;- c(high, k44$conf.int[2])\r\ncancer &lt;- rep(\"BC\", 44)\r\nBC_data_frame &lt;- data.frame(x, cancer, y, low, high)\r\n\r\ncombined_data_frame &lt;- rbind(BC_data_frame, GC_data_frame)\r\n\r\ng5 &lt;- ggplot(combined_data_frame, aes(x, y, color = cancer)) + \r\n  geom_smooth(aes(ymin = low, ymax = high), alpha = 0.2) + \r\n  labs (title = \"xxxxx in GC\/BC\") + \r\n  labs(subtitle = \"xxxxx\") +\r\n  labs(    x        = \"Calendar time\",\r\n           y        = \"Proportion of report per exposure\",\r\n           caption  = \"Error bars indicate 95% confidence interval calculated with Clopper and Pearson's method\" ) +\r\n  scale_color_nejm() + \r\n  geom_point() + \r\n  geom_errorbar(aes(ymin = low, ymax = high), width = 10) + \r\n  scale_x_date(limits = c(as.Date(\"2020-09-15\"), as.Date(\"2024-02-01\")), oob = oob_keep) + \r\n  scale_y_continuous(limits = c(0, 0.3), oob = oob_keep)\r\nplot(g5)\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u306f\u3058\u3081\u306b \u3053\u3093\u306a\u611f\u3058\u306e\u30c7\u30fc\u30bf\u304c\u3042\u308a\u307e\u3057\u305f x\u306f\u6642\u671f\u3000as.Date(&#8220;2024-03-08&#8221;)\u3068\u304b\u306e\u5024\u304c\u5165\u3063\u3066\u3044\u308b\u30d9\u30af\u30bf\u30fc cancer \u306fc(&#8220;GC&#8221;, &#8220;B&#8230;<\/p>\n","protected":false},"author":1,"featured_media":3388,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-3387","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-miscellaneous"],"jetpack_featured_media_url":"https:\/\/plaza.umin.ac.jp\/~OIO\/wp-content\/uploads\/2024\/03\/Rplot-1.png","jetpack_shortlink":"https:\/\/wp.me\/p9b6zl-SD","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/plaza.umin.ac.jp\/~OIO\/index.php?rest_route=\/wp\/v2\/posts\/3387","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/plaza.umin.ac.jp\/~OIO\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/plaza.umin.ac.jp\/~OIO\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/plaza.umin.ac.jp\/~OIO\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/plaza.umin.ac.jp\/~OIO\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3387"}],"version-history":[{"count":0,"href":"https:\/\/plaza.umin.ac.jp\/~OIO\/index.php?rest_route=\/wp\/v2\/posts\/3387\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/plaza.umin.ac.jp\/~OIO\/index.php?rest_route=\/wp\/v2\/media\/3388"}],"wp:attachment":[{"href":"https:\/\/plaza.umin.ac.jp\/~OIO\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3387"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/plaza.umin.ac.jp\/~OIO\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3387"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/plaza.umin.ac.jp\/~OIO\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3387"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}