<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>【graph】タグの記事一覧｜ドクターフント(Dr. Hund)</title>
	<atom:link href="https://brain-storm.space/tag/graph/feed/" rel="self" type="application/rss+xml" />
	<link>https://brain-storm.space</link>
	<description>脳や研究について発信するブログです。This site is for research and statistics.</description>
	<lastBuildDate>Fri, 24 Mar 2023 12:26:31 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.2</generator>

<image>
	<url>https://brain-storm.space/wp-content/uploads/2021/04/cropped-3d0209af428738b78799159b4ce75ad9-32x32.png</url>
	<title>【graph】タグの記事一覧｜ドクターフント(Dr. Hund)</title>
	<link>https://brain-storm.space</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>R, ggplot2を使った論文に使えるグラフテクニック【まとめ】</title>
		<link>https://brain-storm.space/r_graph/962/</link>
					<comments>https://brain-storm.space/r_graph/962/#respond</comments>
		
		<dc:creator><![CDATA[brainblog]]></dc:creator>
		<pubDate>Fri, 24 Mar 2023 12:25:12 +0000</pubDate>
				<category><![CDATA[論文作成・統計]]></category>
		<category><![CDATA[ggplot2]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[R]]></category>
		<guid isPermaLink="false">https://brain-storm.space/?p=962</guid>

					<description><![CDATA[Rではキレイなビジュアルのグラフを無料で作ることができます。高いソフトウェアは不要で、論文に十分使える図ができます！特にggplot2はその使いやすさや見た目のキレイさからとても好評です。 様々なデータがあると思いますが]]></description>
										<content:encoded><![CDATA[
<p>Rではキレイなビジュアルのグラフを<span class="marker">無料で</span>作ることができます。高いソフトウェアは不要で、論文に十分使える図ができます！特にggplot2はその使いやすさや見た目のキレイさからとても好評です。</p>



<p>様々なデータがあると思いますが、一番良く使うのは箱ひげ図や散布図ではないでしょうか。それらをよりわかりやすくビジュアライズしていきたい方向けの基礎的なテクニックです！</p>



<div id="rtoc-mokuji-wrapper" class="rtoc-mokuji-content frame2 preset1 animation-fade rtoc_open default" data-id="962" data-theme="jin-child">
			<div id="rtoc-mokuji-title" class=" rtoc_left">
			<button class="rtoc_open_close rtoc_open"></button>
			<span>Contents</span>
			</div><ol class="rtoc-mokuji decimal_ol level-1"><li class="rtoc-item"><a href="#rtoc-1">ボックスプロット(箱ひげ図)とドットプロットを描く</a><ul class="rtoc-mokuji mokuji_ul level-2"><li class="rtoc-item"><a href="#rtoc-2">baseのboxplotとbeeswarmライブラリを用いて作図する</a></li><li class="rtoc-item"><a href="#rtoc-3">ggplot2を用いてボックスプロットとドットプロットを作図する</a></li><li class="rtoc-item"><a href="#rtoc-4">ggbeeswarmを用いてggplot2のドットを散らばらせる</a></li></ul></li><li class="rtoc-item"><a href="#rtoc-5">ggplot2でバイオリンプロットを描く</a></li><li class="rtoc-item"><a href="#rtoc-6">ggplot2を使って散布図を描く</a><ul class="rtoc-mokuji mokuji_ul level-2"><li class="rtoc-item"><a href="#rtoc-7">散布図と近似直線を描く方法</a></li></ul></li><li class="rtoc-item"><a href="#rtoc-8">複数データはfacet_gridとfacet_wrapを使う</a></li><li class="rtoc-item"><a href="#rtoc-9">geom_barで棒グラフを作図する</a></li><li class="rtoc-item"><a href="#rtoc-10">geom_errorbarで棒グラフと折れ線グラフにエラーバーをつける</a></li><li class="rtoc-item"><a href="#rtoc-11">geom_tileで相関行列のヒートマップをつくる</a></li><li class="rtoc-item"><a href="#rtoc-12">背景の一部(四角)に色をつけるgeom_rect</a></li><li class="rtoc-item"><a href="#rtoc-13">ROC曲線を描く</a></li></ol></div><h2 id="rtoc-1"  class="wp-block-heading">ボックスプロット(箱ひげ図)とドットプロットを描く</h2>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/method_beeswarm_mod-1024x768.jpg" alt="" class="wp-image-863" width="512" height="384"/></figure>



<p>このグラフは<span class="marker">ドットプロット</span>と呼ばれます。箱ひげ図の上にドットプロットを重ねています。</p>



<p>箱ひげ図(box plot)とドットプロット(dot plot)は実際のデータがどのような分布になっているのかみるのに有用です。これで外れ値などもよくわかりますし、誤魔化している感じがない正直なプロットです。</p>



<p>base機能とbeeswarmパッケージを用いた方法とggplot2を使う方法があります。ggplot2を使う場合にはggbeeswarmというパッケージを使うとよりきれいになります。</p>



<h3 id="rtoc-2"  class="wp-block-heading">baseのboxplotとbeeswarmライブラリを用いて作図する</h3>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/box_beeswarm8-1024x1024.jpg" alt="" class="wp-image-738" width="512" height="512"/></figure>



<p>箱ひげ図は、baseと呼ばれるRに元々入っている機能を使ったものです。箱ひげ図はかんたんにかけますが、その後のドットプロットについてはbeeswarmというライブラリを使います。beeswarmは蜂群図とも呼ばれ、点を散らばらせることで視覚的に印象的にみせる効果があります。beeswarmライブラリで簡単に作図をすることができます。</p>



<p>x軸の並び替えもこちらに書いています。</p>



https://brain-storm.space/beeswarm_r/698/



<h3 id="rtoc-3"  class="wp-block-heading">ggplot2を用いてボックスプロットとドットプロットを作図する</h3>



<p>ggplot2を使うのに慣れた人向けの方法です。これは単純なドットプロットを描く方法で、いわゆるbeeswarm(蜂群図)ではありませんが、視覚的効果は十分にあります。</p>



https://brain-storm.space/rggplot2_boxplot_dotplot/620/



<h3 id="rtoc-4"  class="wp-block-heading">ggbeeswarmを用いてggplot2のドットを散らばらせる</h3>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/ggbeeswarm1-1024x1024.jpg" alt="" class="wp-image-874" width="512" height="512"/></figure>



<p>ggplot2でもbeeswarm(蜂群図)を作成することができます。これにはggplot2に加えて、ggbeeswarmというライブラリを使います。点の散らし方にもいくつかの方法があります。</p>



https://brain-storm.space/ggbeeswarm/820/



<h2 id="rtoc-5"  class="wp-block-heading">ggplot2でバイオリンプロットを描く</h2>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/gg_violin_5-1024x1024.jpg" alt="" class="wp-image-881" width="512" height="512"/></figure>



<p>バイオリンプロットも複数のデータを比較する時にとても便利です。とてもキレイな図になります。この中では、バイオリンプロットにドットプロットや箱ひげ図の重ね方を説明しています。バイオリンプロットはggplot2のgeom_violinで描くことができます。</p>



https://brain-storm.space/violin-plot/871/



<h2 id="rtoc-6"  class="wp-block-heading">ggplot2を使って散布図を描く</h2>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/scatterplot12-1024x1024.jpg" alt="" class="wp-image-772" width="512" height="512"/></figure>



<p>相関を数字で出すよりも実際に散布図を出したほうがより直感的にもわかりやすくなります。これも正直な印象を与えることができます。　ggplot2を用いて、geom_pointで散布図を、geom_smoothまたはstat_smoothで近似曲線を表示できます。</p>



<h3 id="rtoc-7"  class="wp-block-heading">散布図と近似直線を描く方法</h3>



https://brain-storm.space/rggplot_scatterplot/751/



<h2 id="rtoc-8"  class="wp-block-heading">複数データはfacet_gridとfacet_wrapを使う</h2>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/facet_wrap7-1024x512.jpg" alt="" class="wp-image-935" width="512" height="256"/></figure>



<p>複数データを一度に表示したいとき、一つ一つ出していたのでは大変です。そんなときはfacet_gridやfacet_wrapを使うと一度にできて、見栄えのあるグラフができます。</p>



<p>またタイトルラベルなどの変え方にも少しテクニックが必要なので、その説明も加えています。</p>



https://brain-storm.space/r_facet/843/



<h2 id="rtoc-9"  class="wp-block-heading">geom_barで棒グラフを作図する</h2>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/07/bargraph7-1024x819.jpg" alt="" class="wp-image-1036" width="512" height="410"/></figure>



<p>棒グラフは最も基本的なグラフの一つです。エクセルでも出来てしまうので、それほど困らないかもしれませんが、ggplot2でも簡単に出来てしまいます。次のリンクで紹介をしています。</p>



https://brain-storm.space/bargraph/1025/



<h2 id="rtoc-10"  class="wp-block-heading">geom_errorbarで棒グラフと折れ線グラフにエラーバーをつける</h2>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/06/errorbar6-1024x614.jpg" alt="" class="wp-image-911" width="512" height="307"/></figure>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/06/errorbar10-1024x614.jpg" alt="" class="wp-image-915" width="512" height="307"/></figure>



<p>棒グラフや折れ線グラフは平均値の大小や推移などを可視化するのによく使われます。データ解析ではそこにエラーバーをつけたりしますが、そのやり方も知らなくては作図ができません。</p>



<p>さらにRでの<span class="marker">標準偏差や標準誤差の算出方法も説明しています</span>。計算で標準誤差などを出せば簡単に作図ができます。</p>



https://brain-storm.space/ggplot2_errorbar/895/



<h2 id="rtoc-11"  class="wp-block-heading">geom_tileで相関行列のヒートマップをつくる</h2>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/06/cormat7-1-1024x819.jpg" alt="" class="wp-image-994" width="512" height="410"/></figure>



<p>相関行列をつくったとき、それをテーブルにしても十分ですが、それを視覚的にわかりやすくするとより印象的な図になります。一目でデータが理解出来るのは、大きなメリットになります。</p>



<p>ggplot2以外のいくつかのパッケージでも描くことはできますが、ggplot2を使った方法を説明しています。それを紹介したのは次のリンクになります。</p>



https://brain-storm.space/corrheatmap/942/



<div class="wp-block-jin-gb-block-border jin-sen"><div class="jin-sen-solid" style="border-width:3px;border-color:#f48789"></div></div>



<p>ggplot2を使うときにデータを横長のデータから縦長のデータへ変換する必要があるときがあります。そんなときはpivot_longerを使うことで簡単に変換をすることができます。これは次の記事で詳細に説明をしています。</p>



https://brain-storm.space/tidyr_gather_pivot_longer/784/



<div class="wp-block-jin-gb-block-border jin-sen"><div class="jin-sen-solid" style="border-width:3px;border-color:#f48789"></div></div>



<p>今回紹介した作図法だけでも、論文のグラフの多くは作図ができると思います。今後もさらなる方法を広めて行きたいと思っています。</p>



<h2 id="rtoc-12"  class="wp-block-heading">背景の一部(四角)に色をつけるgeom_rect</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2023/03/geom_rect_fig6.jpeg" alt="" class="wp-image-1199" width="400" height="400"/></figure>



<p>背景に色をつけて、その部分を強調したり、領域を分けたいことがあります。そんな時はgeom_rectを使います。</p>



https://brain-storm.space/geom_rect/1191/



<h2 id="rtoc-13"  class="wp-block-heading">ROC曲線を描く</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2023/03/roc_comparison_final_8-1.jpeg" alt="ROC曲線" class="wp-image-1251" width="400" height="400"/><figcaption class="wp-element-caption">ROC curve</figcaption></figure>



<p>ROC曲線を書くのは思ったよりも簡単です。Rの初心者でも短時間で書くことができます。AUC(Area under the curve)の比較もあっという間です。</p>



https://brain-storm.space/roc-curve/1212/



<p>今後もさらに追加していく予定です。お役に立ちましたら幸いです。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://brain-storm.space/r_graph/962/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
