Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
171 views
in Technique[技术] by (71.8m points)

r - Display summary column on ggplot2 chart and access single column summary

I tested several ways to display summary statistics on a ggplot2 histogram,and found the simpler ways by using code below:

library(ggplot2)
library(gridExtra)

cols <- c("Hello","Hi" )
a <- summary(Test_data[cols])
grid.table(a)

This produces nice summary table on the chart but with two column name and stat values.

Since chart is only for a particular attribute, I want to use only one column (say 2nd column). To access that, I use the code below:

grid.table(a[1:6,2:2])

This also works well except it just gives summary stat but no column name.

The structure of summary table is 'table':

> str(a)
 'table' chr [1:6, 1:2] "Min.   :124.5  " "1st Qu.:125.0  " "Median :125.0  " ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:6] "" "" "" "" ...
  ..$ : chr [1:2] "Hello" "Hi"

Is it possible to display in above case just access one column summary with column name as well on the chart? Thanks.

EDIT I add sample data below:

mtcars
cols <- c("mpg","cyl")
a <- summary(mtcars[cols])

Now simply i make a visual table with two columns:

library(gridExtra)    
grid.table(a)

enter image description here

as you can see column name mpg and cyl are visible in the visual above. even

grid.table(a[1:6,1:2])

also works similar way.

but if I use below code to get summary stat for only one column, then visual table displays correct stat but with no column name:

grid.table(a[1:6,2:2])

enter image description here

My purpose is to get column name as well on this single column visual.

question from:https://stackoverflow.com/questions/65945269/display-summary-column-on-ggplot2-chart-and-access-single-column-summary

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...