如何将R DataFrame另存为图像

时间:2019-01-03 17:24:15

标签: r gridextra

如何从数据框创建图像?例如:

library(tidyverse)
library(gridExtra)
 df = iris %>% slice(1:4)

我有以下内容,但: 1.我无法将其保存到变量中。它只是在Rstudio的图窗格中弹出。我是否缺少明显的东西?我希望能够将此图引用到变量,以便将其另存为png或其他内容。 2.是否可以删除似乎出现的行号? 3.外观不错,但有没有办法使背景比背景更浅?

gridExtra::grid.table(df)

1 个答案:

答案 0 :(得分:1)

  1. 要保存相关变量,请使用

import React, {Component} from 'react'
import { debounce } from 'lodash'

class TableSearch extends Component {

  //********************************************/

  constructor(props){
    super(props)

    this.state = {
        value: props.value
    }

    this.changeSearch = debounce(this.props.changeSearch, 250)
  }

  //********************************************/

  handleChange = (e) => {
    const val = e.target.value

    this.setState({ value: val }, () => {
      this.changeSearch(val)
    })
  }

  //********************************************/

  render() {

    return (
        <input
            onChange = {this.handleChange}
            value = {this.props.value}
        />
    )
  }

  //********************************************/

}

myTable <- tableGrob(df)

鉴于此,您可以运行

grid.table
# function (...) 
# grid.draw(tableGrob(...))
# <bytecode: 0x10758c078>
# <environment: namespace:gridExtra>
  1. 想要的东西

library(grid)
grid.draw(myTable)
  1. 请参见myTable <- tableGrob(df, rows = NULL) ,尤其是?tableGrob(其源代码清楚地说明了可能的参数;另请参见here)。例如,

ttheme_default

enter image description here