summary <- summary(data)
knitr::kable(summary)
I have the following code in RMD. However, there are more than 20 attributes in the dataset, so that the width of the table generated by summary() is too larger to show the entire table in a row in the page.
Just wondering how could I do to adjust the summary() table?
In addition to r2evans answer, maybe there is another way of reducing the table width :
1- In a table : you should consider transposing the columns into lines. The 6 statistics of summary() should be the columns, and the variables (attributes, according to you) should be the line, e.g.,
summary <- t(summary(data)) # just a basic version, for clarity.
2- In a graphic : if you want all of your attributes renders like columns, maybe you should consider some boxplot (or geom_col and geom_errorbar), with facets or by using an x axis-values for each attribute ? With facet_grid() or facet_wrap(), it's more easy to compare a bunch of attributes than in a big table. If your want to compare things, fix the scales between the facets. If necessary, you can use the grid package, in order to define each facet size and aspect...
Excellent day
Related
I'm trying to make a box plot that will show columns PSS_pre and PSS_post
At the moment I have the following code:
boxplot(PSS_post~intervention)
This code shows the column PSS_post, although I can change PSS_post to PSS_pre and it will show me the column for PSS_pre. How can I make it show me both colums at the same time?
Consider plotting a list with the 2 elements.
pp_list <- list(Pre = PSS_pre~intervention, post=PSS_post~intervention)
boxplot(pp_list)
I have read the Cufflinks examples. The only subplots examples are generated from a single DataFrame with a subplots=True parameter and an optional shape parameter (i.e. df.iplot(..., subplots=True, shape=(...), ...). As I understand it, the mechanism is that when subplots=True is provided, each column of the DataFrame is plotted as a subplot.
Now, about heatmaps in Cufflinks. The example in the same link shows that the DataFrame of a heatmap of N * M is simply an N * M DataFrame where the column names and indexes tells the x and y coordiates and the values are the "heat" of each cell of the grid.
Combining the two, it seems that if I have two heatmaps (thus two DataFrames), I cannot plot both in a subplot-fashion, because subplots require a single DataFrame and I cannot combine two heatmap DataFrames into one.
Anyone has any idea how it might work?
BTW, I also tried plotly.offline.iplot(..., subplots=True, ...) and the parameter is not supported.
EDIT
There is another question (from me, too) asking about doing the same in plotly, which got answered. So if you are working w/ plotly directly then that's the answer you might want to take a look.
This question is about using Cufflinks to achieve the same. It still seems impossible (or at least very difficult) to me.
You can use the following:
import cufflinks as cf
df1=cf.datagen.heatmap()
df2=cf.datagen.heatmap()
cf.subplots([df1.figure(kind='heatmap'),df2.figure(kind='heatmap')]).iplot()
You can do this with as many heatmaps, and you can also use the shape parameters.
I have the following plot:
plot.ts(returns)
I have another dataframe ma_sd which contains the rolling SD from moving averages of the above returns. The df is structured exactly like returns. Is there a simple way to add each line to the corresponding plots?
lines(1:N, ma_sd) seemed intuitive, but it does not work.
Thanks
The only way I can see you doing this is to plot them separately. This code is a bit clunky but will allow you full flexibility to be able to specify labels and axis ranges. You can build on this.
par(mfrow=c(3,1),oma=c(5,4,4,2),mar=c(0,0,0,0))
time<-as.data.frame(matrix(c(1:length(returns[,1])),length(returns[,1]),3))
plot(time[,1],returns[,1],type='l',xaxt='n')
points(time[,1],ma_sd[,1],type='l',col='red')
plot(time[,2],returns[,2],type='l',xaxt='n')
points(time[,2],ma_sd[,2],type='l',col='red')
plot(time[,3],returns[,3],type='l')
points(time[,3],ma_sd[,3],type='l',col='red')
I found an interesting thread about plotting but I'm not happy with the answer. I would like to plot different amount of rows on the same graph. Just giving me the possibility to add as much rows as I want to.
I'd like to use glopts library but I am open for any other. First of all I want to plot those rows into pdf file. The script which I want to modify is:
which_rows <- c(12,156,4432) ## I want to choose which row I want to plot
pdf(file='Plots'.pdf)
x <- 1:(ncol(data_plot)-1) ## Can it be changed to use the name of the columns instead of pure numbers ?
for(i in which_rows){
## create new pdf page BUT I WANT TO PLOT IT ON THE SAME GRAPH!
plot(x=x,y=data_plot[i,-1],type='b',main=data_plot[i,1],xlab='columns',ylab='Intensity')
}
# closing pdf
dev.off()
Can you help me to modify this script to print just all of the rows which I decide on the same graph ? Would be great if you show me how I can jsut add new page in this pdf file using the other set of rows like which_rows2.
Of course each plot should has diffent colour or something.
Edit:
use points()to add points to the existing plot
It looks like grid.arrange() ignores the name attribute of tableGrob. Let's say I want to plot tables with titles...
baz<-lapply(seq(3),function(ii)
tableGrob(format(matrix(runif(8),nrow=2,
dimnames=list(LETTERS[1:2],letters[1:4])),digits=3),
name=paste0('n',ii)));
This plots them but without titles: do.call(grid.arrange,c(baz,nrow=1))
It seems like overkill to screw around with creating lists of textGrobs, calculating their height, etc. I just want to force there to be an extra line above the header of each table, displaying the name I gave to that table. Or some built-in argument to do so.