R中的数据可视化 [英] Data visualization in R

查看:121
本文介绍了R中的数据可视化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要可视化的数据来自实验(T1-T8代表大脑的不同部分),如下所示:

The data to be visualized is from an experiment (T1-T8 represents different sections of the brain) and is as follows:

    [[Block1]]
              sum
       [T1,]   6
       [T2,]   6
       [T3,]   4
       [T4,]   5
       [T5,]   8
       [T6,]   9
       [T7,]   8
       [T8,]   6

    [[Block2]]
              sum
       [T1,]   3
       [T2,]   3
       [T3,]   4
       [T4,]   5
       [T5,]   4
       [T6,]   2
       [T7,]   1
       [T8,]   5

    [[Block3]]
              sum
       [T1,]   3
       [T2,]   3
       [T3,]   4
       [T4,]   2
       [T5,]   4
       [T6,]   8
       [T7,]   3
       [T8,]   1   

   [[Block4]]
              sum
       [T1,]   6
       [T2,]   5
       [T3,]   4
       [T4,]   3
       [T5,]   9
       [T6,]   8
       [T7,]   2
       [T8,]   6  

   [[Block5]]
              sum
       [T1,]   8
       [T2,]   3
       [T3,]   4
       [T4,]   5
       [T5,]   7
       [T6,]   6
       [T7,]   2
       [T8,]   2 

   [[Block6]]
              sum
       [T1,]   10
       [T2,]   9
       [T3,]   6
       [T4,]   8
       [T5,]   9
       [T6,]   4
       [T7,]   6
       [T8,]   7

依此类推..对于100多个块..

and so on.. For more than 100 blocks..

我想以以下方式可视化数据,以查看每个区域每个区块的整体价值

I would like to visualize the data in the following way to see the overall value in each region for very block..

对于一个区块,我得到一条线如下图所示:

For one block I get a line plot as shown below:

但是将其可视化为100个块是很繁琐的。用R.将其视为单个绘图的最佳方法是什么?

But it is tedious to visualize the same for 100 blocks.. What would be the best method to view it as a single plot using R..I tried doing it with heat maps but I would rather visualize them as a graph..

最后,它应该类似于(我有一个大概的数字)。我不确定如何在R中针对单个绘图中的多个块或通过其他更好的方式来可视化它:

In the end it should be something like ( I have a rough figure of it).. Iam not sure how to do this in R for several blocks in a single plot or some other better way to visualize it:

推荐答案

这基本上是 ggplot2

This is basically what ggplot2 is for, in my opinion. Here is a recreation of your data, along with a very basic plot.

# Recreate your data.
data<-c(6,6,4,5,8,9,8,6,3,3,4,5,4,2,1,5,3,3,4,2,4,8,3,1,6,5,4,3,9,8,2,6,8,3,4,5,7,6,2,2,10,9,6,8,9,4,6,7)
list<-split(data,rep(1:6,each=8))
names(list)<-paste0('Block',1:6)

library(ggplot2)
library(reshape2)
dat<-melt(list)[2:1]
names(dat)<-c('Block','Value')
dat$brain.section<-rep(1:8,6)

ggplot(dat,aes(x=brain.section,y=Value,group=Block)) + geom_line() + facet_grid(Block~.)

您可以真正欣赏颜色和布局,但是您如果您不知道 ggplot2 ,可以将其用作入门。

You can get really fancy with colours and layout, but you can use that as something to get you started if you don't know ggplot2.

这真是热相同数据的地图看起来像是

Here is what a heat map of the same data would look like

ggplot(dat,aes(x=brain.section,fill=Value,y=Block)) + geom_tile() 

这篇关于R中的数据可视化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆