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)
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])
My purpose is to get column name as well on this single column visual.