data.frame的行颜色 [英] row color of data.frame

查看:400
本文介绍了data.frame的行颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图根据文本值(Type)的列中的值突出data.frame(testdf)的行

  testdf< -data.frame(Type = c(NON_BRAND,BRAND,BRAND,NON_BRAND),CA = c(500,890,780,240),Campaign = c ,B,A,B))

使用热图,因为我需要根据类型列中的单词整个行的颜色。 (例如,NON_BRAND行的颜色为蓝色,BRAND行为黄色)。



我的输出是使用R Markdown的PDF或html文件。



有没有人知道是否有这样的可能性为data.frame着色?



任何帮助将非常感激。

解决方案

lazyWeave 是一个有点笨重,在它的当前CRAN版本,但我正在努力,希望在一个月内有更新,这将照顾它的一些怪异。 / p>

我觉得 xtable 也可以这样做,虽然我不记得具体细节。如果 xtable 会这样做,我建议大部分时间使用。它比 lazyWeave 有点干净。

  --- 
标题:Untitled
输出:html_document
---

库(lazyWeave)
库(lazyReportFormat = html)
testdf< -data.frame(Type = c(NON_BRAND,BRAND,BRAND,NON_BRAND),
CA = c(500,890,780,240),
Campaign = c(A,B,A,B))
```

```{r,results ='asis'}
lazy.matrix(testdf,
rcol = 1:nrow(testdf),
usecol = ifelse(testdf $ Type ==NON_BRAND,blue,yellow))
```


I'm trying to highlight the rows of the data.frame (testdf) according to the value in the column with the text values ("Type")

testdf<-data.frame(Type=c("NON_BRAND", "BRAND", "BRAND", "NON_BRAND"),CA=c(500,890,780,240), Campaign=c("A", "B", "A", "B"))

I can't achieve this using heatmap, as I need to color the whole row according to the word in the column "Type". (NON_BRAND rows color in blue and BRAND rows in yellow, for example).

My output is a pdf or html file using R Markdown.

Does anyone know if there is such possibility to color the data.frame?

Any help would be greatly appreciated.

解决方案

lazyWeave is a little clunky in it's current CRAN version, but I'm working on it and hope to have an update within a month or so that will take care of some of it's oddities.

I feel like xtable can do this too, though I can't remember the specifics. If xtable will do it, I'd recommend using that most of the time. It's a bit cleaner than lazyWeave.

---
title: "Untitled"
output: html_document
---

```{r}
library(lazyWeave)
options(lazyReportFormat="html")
testdf<-data.frame(Type=c("NON_BRAND", "BRAND", "BRAND", "NON_BRAND"),
                   CA=c(500,890,780,240), 
                   Campaign=c("A", "B", "A", "B"))
```

```{r, results='asis'}
lazy.matrix(testdf,
            rcol= 1:nrow(testdf),
            usecol = ifelse(testdf$Type == "NON_BRAND", "blue", "yellow"))
```

这篇关于data.frame的行颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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