使用R将数据框转换为表吗? [英] Translate a dataframe into a table using R plotly?

查看:341
本文介绍了使用R将数据框转换为表吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难理解R中的绘图表的工作方式.我不是一位经验丰富的程序员,因此我的问题可能看起来很幼稚.

I am having a hard time understanding the workings of plotly tables in R. I am not an experienced programmer, thus my question may look naive.

请考虑以下数据框:

data<-data.frame(
SeqName=c("1", "2", "3", "4", "5", "6"),
Length=c("440", "511", "1087", "686", "867", "632"),
Cys=c("3", "2", "2", "2", "2", "4"),
NT=c("[NA]", "[B]", "[B]", "[B]", "[B]", "[B]"),
NR=c("[NA]", "[B][M]", "[B]", "[B][M]", "[B][M]", "[NA]"),
RefSeq=c("[NA]", "[B][M]", "[B]", "[B][M]", "[B][M]", "[NA]")
)

我可以使用以下方法创建等效的绘图表:

I can create the equivalent plotly table using the following:

plot_ly(
    type = 'table',
    header = list(
        values = list(list('<b>SeqName<b>'),
                      list('<b>Length<b>'),
                      list('<b>Cys<b>'),
                      list('<b>NT<b>'),
                      list('<b>NR<b>'),
                      list('<b>RefSeq<b>'))),
        cells = list(values = list(
        c("1", "2", "3", "4", "5", "6"),
        c("440", "511", "1087", "686", "867", "632"),
        c("3", "2", "2", "2", "2", "4"),
        c("[NA]", "[B]", "[B]", "[B]", "[B]", "[B]"),
        c("[NA]", "[B][M]", "[B]", "[B][M]", "[B][M]", "[NA]"),
        c("[NA]", "[B][M]", "[B]", "[B][M]", "[B][M]", "[NA]"))))

但是,我不能直接跳.例如,我无法执行以下操作:

However, I cannot make a direct jump. For instance, I cannot get the following to work:

plot_ly(type = 'table', header = list(values=names(data)), cells=list(list(values=data)))

请,任何人都可以澄清原因吗?预先感谢.

Please, could anyone clarify why? Thanks in advance.

推荐答案

似乎plot_ly期望仅对指定给cells参数的列表的values参数使用未命名的列表,因此您可以将其传递给它在data.frame上使用unname:

It seems that plot_ly is expecting an unnamed list only for the values argument of the list given to the cells argument, so you can just pass this to it by using unname on your data.frame:

plot_ly(type="table",header=list(values=names(data)), cells=list(values=unname(data))) 

这篇关于使用R将数据框转换为表吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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