colour

How to add different segment, annotation and color to each facet in ggplot

今回もRネタである.論文の図を作成していて,ggplot2のfacetを使用して作成した図の中のfacet毎に異なる有意差を示す群を線分で結んで,その上にasteriskを色を変えてつけようとしたところ,結構苦労したので忘れないうちにまとめておく.annotate()というのもあるが,これだとすべてのfacetに同じ内容が入ってしまう.今回の目的であるfacetによって異なる内容の注釈を入れるためには,geom_segmentやgeom_textを使う. Table of Contents References Data Preparation Tukey multiple comparison TukeyHSD テューキーの方法による多重比較 Boxplot by ggplot2 Calculate mean and SE geom_jitter geom_point Add mean bar Add segment and asterisk to Drug2 facet of boxplot Dataframe for annotation Add segment with geom_segment and asterisk with geom_text (black) Add segment with geom_segment and asterisk with geom_text (color) Barplot by ggplot2 Barplot Add segment and asterisk to Drug2 facet of barplot Dataframe for annotation Add segment with geom_segment and asterisk with geom_text (color) Combine boxplot and barplot into the same graphic References ggplot2を使って、注釈を入れる-2 Adding different annotation to each facet in ggplot Add a segment only to one facet using ggplot2 Data Preparation まず,架空のデータを作成する.Drug1とDrug2を投与して1日後と7日後の物質Xの血中濃度変化を対照,つまり投与前と比較するという実験において,Drug1では差がなく,Drug2では差があるという結果にする.