R - specify columns in grid.table to be bold
I've got a table with 3 columns and I'm using grid.table to generate a pdf version. I want two of those columns to be in bold and keep the other one as plain text. I've not found a general solution to this, the grid.table cran page only shows you how to edit fontface for rows or specific cells.
Using a small sample dataset (due to sensitivity):
> dput(Data)
structure(list(Location = structure(c(1L, 1L, 1L, 2L, 2L, 3L), .Label = c("A", "B", "C"), class = "factor"),
Subloc = structure(1:6, .Label = c("A1","A2", "A3", "B1", "B2", "C1"),
class = "factor"), Type = structure(c(3L,3L, 3L, 1L, 1L, 2L),
.Label = c("Alpha", "Beta", "Meta"),
class = "factor")),
class = "data.frame",
row.names = c(NA, -6L))
My existing code:
maxrow <- c(30);
npages <- ceiling(nrow(Data)/maxrow);
pdf(paste0("DATE.pdf"), height = 11, width = 10)
idx <- seq(1, maxrow)
grid.table(Data[idx, ], rows = NULL, theme = ttheme_minimal(core=list(fg_params=list(hjust=0, x=0.1, fontface = c("bold"))),
rowhead=list(fg_params=list(hjust=0, x=0)), colhead=list(fg_params=list(fontsize = 14, col="#660066", fontface="bold"))))
for (i in 2:npages){
grid.newpage();
if(i*maxrow <= nrow(Data)) {
idx <- seq(1+((i-1)*maxrow), i*maxrow)} else{
idx <- seq(1+((i-1)*maxrow), nrow(Data))}grid.table(Data[idx,], rows =NULL,theme = ttheme_minimal(core=list(fg_params=list(hjust=0, x=0.1)), rowhead=list(fg_params=list(hjust=0, x=0)),colhead=list(fg_params=list(fontsize = 14, col="#660066", fontface="bold"))))
}dev.off()
I want to make the data inside the Location and Type columns (not the column headers) to be in bold. I've managed to make all the column contents bold in the fg_params=list wrapper, but don't know how to specify the columns I want this treatment for.
r gridextra r-grid
add a comment |
I've got a table with 3 columns and I'm using grid.table to generate a pdf version. I want two of those columns to be in bold and keep the other one as plain text. I've not found a general solution to this, the grid.table cran page only shows you how to edit fontface for rows or specific cells.
Using a small sample dataset (due to sensitivity):
> dput(Data)
structure(list(Location = structure(c(1L, 1L, 1L, 2L, 2L, 3L), .Label = c("A", "B", "C"), class = "factor"),
Subloc = structure(1:6, .Label = c("A1","A2", "A3", "B1", "B2", "C1"),
class = "factor"), Type = structure(c(3L,3L, 3L, 1L, 1L, 2L),
.Label = c("Alpha", "Beta", "Meta"),
class = "factor")),
class = "data.frame",
row.names = c(NA, -6L))
My existing code:
maxrow <- c(30);
npages <- ceiling(nrow(Data)/maxrow);
pdf(paste0("DATE.pdf"), height = 11, width = 10)
idx <- seq(1, maxrow)
grid.table(Data[idx, ], rows = NULL, theme = ttheme_minimal(core=list(fg_params=list(hjust=0, x=0.1, fontface = c("bold"))),
rowhead=list(fg_params=list(hjust=0, x=0)), colhead=list(fg_params=list(fontsize = 14, col="#660066", fontface="bold"))))
for (i in 2:npages){
grid.newpage();
if(i*maxrow <= nrow(Data)) {
idx <- seq(1+((i-1)*maxrow), i*maxrow)} else{
idx <- seq(1+((i-1)*maxrow), nrow(Data))}grid.table(Data[idx,], rows =NULL,theme = ttheme_minimal(core=list(fg_params=list(hjust=0, x=0.1)), rowhead=list(fg_params=list(hjust=0, x=0)),colhead=list(fg_params=list(fontsize = 14, col="#660066", fontface="bold"))))
}dev.off()
I want to make the data inside the Location and Type columns (not the column headers) to be in bold. I've managed to make all the column contents bold in the fg_params=list wrapper, but don't know how to specify the columns I want this treatment for.
r gridextra r-grid
add a comment |
I've got a table with 3 columns and I'm using grid.table to generate a pdf version. I want two of those columns to be in bold and keep the other one as plain text. I've not found a general solution to this, the grid.table cran page only shows you how to edit fontface for rows or specific cells.
Using a small sample dataset (due to sensitivity):
> dput(Data)
structure(list(Location = structure(c(1L, 1L, 1L, 2L, 2L, 3L), .Label = c("A", "B", "C"), class = "factor"),
Subloc = structure(1:6, .Label = c("A1","A2", "A3", "B1", "B2", "C1"),
class = "factor"), Type = structure(c(3L,3L, 3L, 1L, 1L, 2L),
.Label = c("Alpha", "Beta", "Meta"),
class = "factor")),
class = "data.frame",
row.names = c(NA, -6L))
My existing code:
maxrow <- c(30);
npages <- ceiling(nrow(Data)/maxrow);
pdf(paste0("DATE.pdf"), height = 11, width = 10)
idx <- seq(1, maxrow)
grid.table(Data[idx, ], rows = NULL, theme = ttheme_minimal(core=list(fg_params=list(hjust=0, x=0.1, fontface = c("bold"))),
rowhead=list(fg_params=list(hjust=0, x=0)), colhead=list(fg_params=list(fontsize = 14, col="#660066", fontface="bold"))))
for (i in 2:npages){
grid.newpage();
if(i*maxrow <= nrow(Data)) {
idx <- seq(1+((i-1)*maxrow), i*maxrow)} else{
idx <- seq(1+((i-1)*maxrow), nrow(Data))}grid.table(Data[idx,], rows =NULL,theme = ttheme_minimal(core=list(fg_params=list(hjust=0, x=0.1)), rowhead=list(fg_params=list(hjust=0, x=0)),colhead=list(fg_params=list(fontsize = 14, col="#660066", fontface="bold"))))
}dev.off()
I want to make the data inside the Location and Type columns (not the column headers) to be in bold. I've managed to make all the column contents bold in the fg_params=list wrapper, but don't know how to specify the columns I want this treatment for.
r gridextra r-grid
I've got a table with 3 columns and I'm using grid.table to generate a pdf version. I want two of those columns to be in bold and keep the other one as plain text. I've not found a general solution to this, the grid.table cran page only shows you how to edit fontface for rows or specific cells.
Using a small sample dataset (due to sensitivity):
> dput(Data)
structure(list(Location = structure(c(1L, 1L, 1L, 2L, 2L, 3L), .Label = c("A", "B", "C"), class = "factor"),
Subloc = structure(1:6, .Label = c("A1","A2", "A3", "B1", "B2", "C1"),
class = "factor"), Type = structure(c(3L,3L, 3L, 1L, 1L, 2L),
.Label = c("Alpha", "Beta", "Meta"),
class = "factor")),
class = "data.frame",
row.names = c(NA, -6L))
My existing code:
maxrow <- c(30);
npages <- ceiling(nrow(Data)/maxrow);
pdf(paste0("DATE.pdf"), height = 11, width = 10)
idx <- seq(1, maxrow)
grid.table(Data[idx, ], rows = NULL, theme = ttheme_minimal(core=list(fg_params=list(hjust=0, x=0.1, fontface = c("bold"))),
rowhead=list(fg_params=list(hjust=0, x=0)), colhead=list(fg_params=list(fontsize = 14, col="#660066", fontface="bold"))))
for (i in 2:npages){
grid.newpage();
if(i*maxrow <= nrow(Data)) {
idx <- seq(1+((i-1)*maxrow), i*maxrow)} else{
idx <- seq(1+((i-1)*maxrow), nrow(Data))}grid.table(Data[idx,], rows =NULL,theme = ttheme_minimal(core=list(fg_params=list(hjust=0, x=0.1)), rowhead=list(fg_params=list(hjust=0, x=0)),colhead=list(fg_params=list(fontsize = 14, col="#660066", fontface="bold"))))
}dev.off()
I want to make the data inside the Location and Type columns (not the column headers) to be in bold. I've managed to make all the column contents bold in the fg_params=list wrapper, but don't know how to specify the columns I want this treatment for.
r gridextra r-grid
r gridextra r-grid
edited Nov 21 '18 at 11:10
Pryore
asked Nov 21 '18 at 10:31
PryorePryore
199110
199110
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
try this
library(gridExtra)
tt <- ttheme_default()
tt$core$fg_params <- list(fontface=matrix(c(1,2,3), ncol=ncol(d),nrow=nrow(d),byrow=TRUE))
grid.table(d, theme=tt)
Code output:
Hi @user10697133 That is a cool first answer! Consider also that @Pryore would like to have the headers in plain font, so something like thislist(fg_params=list(fontface='plain'))
forcolhead
could be integrated in your answer.
– Valentin
Nov 24 '18 at 21:51
@user10697133, thanks for your contribution. Just one thing though, how do I specify the fontface of either of those 3 columns. By itself, your code doesn't make my first and second column bold. Maybe I'm missing something, could you clarify please?
– Pryore
Nov 26 '18 at 9:24
I've basically tried to assign fontface to the matrix indices after using the code you wrote for me, i.e.tt$core$fg_params <- list(fontface = c("bold","plain","bold"))
, but this transforms the core text by row where each 1st and 3rd row of my data is bold rather than by column. Thanks for your help once again
– Pryore
Nov 26 '18 at 9:33
@Pryore that's why you need a matrix (of the same size as your core content); a vector will get recycled row-wise.
– user10697133
Nov 26 '18 at 20:01
It works with the sample data I've given, but having problems with my main dataset. What appears to be happening is while the matrix (using the index c(1,2,3) you suggested) is correctly generating, the actual aesthetic changes are not occuring. Instead all the core content defaults to plain-text. So I tried an alternative of c("bold","plain","bold") and everything in my table turns bold.
– Pryore
Nov 27 '18 at 9:32
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53410102%2fr-specify-columns-in-grid-table-to-be-bold%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
try this
library(gridExtra)
tt <- ttheme_default()
tt$core$fg_params <- list(fontface=matrix(c(1,2,3), ncol=ncol(d),nrow=nrow(d),byrow=TRUE))
grid.table(d, theme=tt)
Code output:
Hi @user10697133 That is a cool first answer! Consider also that @Pryore would like to have the headers in plain font, so something like thislist(fg_params=list(fontface='plain'))
forcolhead
could be integrated in your answer.
– Valentin
Nov 24 '18 at 21:51
@user10697133, thanks for your contribution. Just one thing though, how do I specify the fontface of either of those 3 columns. By itself, your code doesn't make my first and second column bold. Maybe I'm missing something, could you clarify please?
– Pryore
Nov 26 '18 at 9:24
I've basically tried to assign fontface to the matrix indices after using the code you wrote for me, i.e.tt$core$fg_params <- list(fontface = c("bold","plain","bold"))
, but this transforms the core text by row where each 1st and 3rd row of my data is bold rather than by column. Thanks for your help once again
– Pryore
Nov 26 '18 at 9:33
@Pryore that's why you need a matrix (of the same size as your core content); a vector will get recycled row-wise.
– user10697133
Nov 26 '18 at 20:01
It works with the sample data I've given, but having problems with my main dataset. What appears to be happening is while the matrix (using the index c(1,2,3) you suggested) is correctly generating, the actual aesthetic changes are not occuring. Instead all the core content defaults to plain-text. So I tried an alternative of c("bold","plain","bold") and everything in my table turns bold.
– Pryore
Nov 27 '18 at 9:32
|
show 1 more comment
try this
library(gridExtra)
tt <- ttheme_default()
tt$core$fg_params <- list(fontface=matrix(c(1,2,3), ncol=ncol(d),nrow=nrow(d),byrow=TRUE))
grid.table(d, theme=tt)
Code output:
Hi @user10697133 That is a cool first answer! Consider also that @Pryore would like to have the headers in plain font, so something like thislist(fg_params=list(fontface='plain'))
forcolhead
could be integrated in your answer.
– Valentin
Nov 24 '18 at 21:51
@user10697133, thanks for your contribution. Just one thing though, how do I specify the fontface of either of those 3 columns. By itself, your code doesn't make my first and second column bold. Maybe I'm missing something, could you clarify please?
– Pryore
Nov 26 '18 at 9:24
I've basically tried to assign fontface to the matrix indices after using the code you wrote for me, i.e.tt$core$fg_params <- list(fontface = c("bold","plain","bold"))
, but this transforms the core text by row where each 1st and 3rd row of my data is bold rather than by column. Thanks for your help once again
– Pryore
Nov 26 '18 at 9:33
@Pryore that's why you need a matrix (of the same size as your core content); a vector will get recycled row-wise.
– user10697133
Nov 26 '18 at 20:01
It works with the sample data I've given, but having problems with my main dataset. What appears to be happening is while the matrix (using the index c(1,2,3) you suggested) is correctly generating, the actual aesthetic changes are not occuring. Instead all the core content defaults to plain-text. So I tried an alternative of c("bold","plain","bold") and everything in my table turns bold.
– Pryore
Nov 27 '18 at 9:32
|
show 1 more comment
try this
library(gridExtra)
tt <- ttheme_default()
tt$core$fg_params <- list(fontface=matrix(c(1,2,3), ncol=ncol(d),nrow=nrow(d),byrow=TRUE))
grid.table(d, theme=tt)
Code output:
try this
library(gridExtra)
tt <- ttheme_default()
tt$core$fg_params <- list(fontface=matrix(c(1,2,3), ncol=ncol(d),nrow=nrow(d),byrow=TRUE))
grid.table(d, theme=tt)
Code output:
edited Nov 26 '18 at 20:00
answered Nov 23 '18 at 20:28
user10697133user10697133
362
362
Hi @user10697133 That is a cool first answer! Consider also that @Pryore would like to have the headers in plain font, so something like thislist(fg_params=list(fontface='plain'))
forcolhead
could be integrated in your answer.
– Valentin
Nov 24 '18 at 21:51
@user10697133, thanks for your contribution. Just one thing though, how do I specify the fontface of either of those 3 columns. By itself, your code doesn't make my first and second column bold. Maybe I'm missing something, could you clarify please?
– Pryore
Nov 26 '18 at 9:24
I've basically tried to assign fontface to the matrix indices after using the code you wrote for me, i.e.tt$core$fg_params <- list(fontface = c("bold","plain","bold"))
, but this transforms the core text by row where each 1st and 3rd row of my data is bold rather than by column. Thanks for your help once again
– Pryore
Nov 26 '18 at 9:33
@Pryore that's why you need a matrix (of the same size as your core content); a vector will get recycled row-wise.
– user10697133
Nov 26 '18 at 20:01
It works with the sample data I've given, but having problems with my main dataset. What appears to be happening is while the matrix (using the index c(1,2,3) you suggested) is correctly generating, the actual aesthetic changes are not occuring. Instead all the core content defaults to plain-text. So I tried an alternative of c("bold","plain","bold") and everything in my table turns bold.
– Pryore
Nov 27 '18 at 9:32
|
show 1 more comment
Hi @user10697133 That is a cool first answer! Consider also that @Pryore would like to have the headers in plain font, so something like thislist(fg_params=list(fontface='plain'))
forcolhead
could be integrated in your answer.
– Valentin
Nov 24 '18 at 21:51
@user10697133, thanks for your contribution. Just one thing though, how do I specify the fontface of either of those 3 columns. By itself, your code doesn't make my first and second column bold. Maybe I'm missing something, could you clarify please?
– Pryore
Nov 26 '18 at 9:24
I've basically tried to assign fontface to the matrix indices after using the code you wrote for me, i.e.tt$core$fg_params <- list(fontface = c("bold","plain","bold"))
, but this transforms the core text by row where each 1st and 3rd row of my data is bold rather than by column. Thanks for your help once again
– Pryore
Nov 26 '18 at 9:33
@Pryore that's why you need a matrix (of the same size as your core content); a vector will get recycled row-wise.
– user10697133
Nov 26 '18 at 20:01
It works with the sample data I've given, but having problems with my main dataset. What appears to be happening is while the matrix (using the index c(1,2,3) you suggested) is correctly generating, the actual aesthetic changes are not occuring. Instead all the core content defaults to plain-text. So I tried an alternative of c("bold","plain","bold") and everything in my table turns bold.
– Pryore
Nov 27 '18 at 9:32
Hi @user10697133 That is a cool first answer! Consider also that @Pryore would like to have the headers in plain font, so something like this
list(fg_params=list(fontface='plain'))
for colhead
could be integrated in your answer.– Valentin
Nov 24 '18 at 21:51
Hi @user10697133 That is a cool first answer! Consider also that @Pryore would like to have the headers in plain font, so something like this
list(fg_params=list(fontface='plain'))
for colhead
could be integrated in your answer.– Valentin
Nov 24 '18 at 21:51
@user10697133, thanks for your contribution. Just one thing though, how do I specify the fontface of either of those 3 columns. By itself, your code doesn't make my first and second column bold. Maybe I'm missing something, could you clarify please?
– Pryore
Nov 26 '18 at 9:24
@user10697133, thanks for your contribution. Just one thing though, how do I specify the fontface of either of those 3 columns. By itself, your code doesn't make my first and second column bold. Maybe I'm missing something, could you clarify please?
– Pryore
Nov 26 '18 at 9:24
I've basically tried to assign fontface to the matrix indices after using the code you wrote for me, i.e.
tt$core$fg_params <- list(fontface = c("bold","plain","bold"))
, but this transforms the core text by row where each 1st and 3rd row of my data is bold rather than by column. Thanks for your help once again– Pryore
Nov 26 '18 at 9:33
I've basically tried to assign fontface to the matrix indices after using the code you wrote for me, i.e.
tt$core$fg_params <- list(fontface = c("bold","plain","bold"))
, but this transforms the core text by row where each 1st and 3rd row of my data is bold rather than by column. Thanks for your help once again– Pryore
Nov 26 '18 at 9:33
@Pryore that's why you need a matrix (of the same size as your core content); a vector will get recycled row-wise.
– user10697133
Nov 26 '18 at 20:01
@Pryore that's why you need a matrix (of the same size as your core content); a vector will get recycled row-wise.
– user10697133
Nov 26 '18 at 20:01
It works with the sample data I've given, but having problems with my main dataset. What appears to be happening is while the matrix (using the index c(1,2,3) you suggested) is correctly generating, the actual aesthetic changes are not occuring. Instead all the core content defaults to plain-text. So I tried an alternative of c("bold","plain","bold") and everything in my table turns bold.
– Pryore
Nov 27 '18 at 9:32
It works with the sample data I've given, but having problems with my main dataset. What appears to be happening is while the matrix (using the index c(1,2,3) you suggested) is correctly generating, the actual aesthetic changes are not occuring. Instead all the core content defaults to plain-text. So I tried an alternative of c("bold","plain","bold") and everything in my table turns bold.
– Pryore
Nov 27 '18 at 9:32
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53410102%2fr-specify-columns-in-grid-table-to-be-bold%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown