Hi,
I have plotted multiple plots in a shiny app. But it comes one below the other. But I want to arrange it so that viewing becomes easy. How can I customize it as per my requirements?
Hi you can put those plots in columns
column(width=6, plotOutput(outputid =.....)),
column(width=6, plotOutput(outputid =.....)),
column(width=6, plotOutput(outputid =.....)),
column(width=6, plotOutput(outputid =.....)),
this will be 2 by 2 = 4 plots, you can adjust and make it more plots
hope helpful
GP
Please see this article:
https://shiny.rstudio.com/articles/layout-guide.html
and library(gridlayout)
:
Oh great. thank you very much.
Regards,
NP
Sure I will go through it. Thanks a lot
Regards,
NP
Hi
Just an add on question. How can I give spacing between plots in the dashboard?
Hi try inserting between
div(style = "margin-top:20px")
Adjust px as required
Hope helps
Should I try like shown below:
column(width=6, plotOutput(outputid =.....)),
div(style = "margin-top:20px"),
column(width=6, plotOutput(outputid =.....)),
column(width=6, plotOutput(outputid =.....)),
column(width=6, plotOutput(outputid =.....))
Hi kindly draw your requirements in a paper roughly and post the image, we may get a better solution quickly
Hi Here you go. you have option to adjust the margin as well as number of plots per row and per column. kinly check and confirm
library(graphics)
df <- dplyr::select_if(iris,is.numeric)
r <- 2
c <- 2
par(mfrow=c(r,c)) #get in 2 rows and 2 columns (first one is row)
par(mar=c(2, 2, 2, 2)) # #par("mar") (bottom, left, top, right) for margin
my_text <- "This is my first plot"
boxplot(x = df[ ,1],
main = my_text,
labels = TRUE,
col = "#87CEFA",
border = "black",
notch = TRUE
)
my_text <- "This is my Second plot"
hist(x = iris[[1]],
main = my_text,
col = "#87CEFA",
border='black',
xlab = names(iris[1])
)
my_text <- "This is my Third plot"
model <- lm(iris[[2]] ~ iris[[1]], data = df)
plot(x=iris[[1]],
y=iris[[2]],
main = my_text,
pch = 19,
col = "steelblue",
type = 'p',
xlab = names(iris[1]),
ylab = names(iris[2])
)+ abline(model)
my_text <- "This is my Fourth plot"
plot(x=iris[[1]],
main = my_text,
pch = 19,
col = "steelblue",
type = 'l',
xlab = names(iris[1]),
ylab = names(iris[2])
)
Do these commands work with ggplot
package?
Hi
I checked once again, in fact, these plots are made with package built-in R studio (graphics )
these commands do not require ggplot.
if you want to use ggplot2 function, in that case,
since your concern is only arranging plots in rows and columns, you may run these two lines of code to define row and column and margin, and then run 4 ggplots
r <- 2
c <- 2
par(mfrow=c(r,c)) #get in 2 rows and 2 columns (first one is row)
par(mar=c(2, 2, 2, 2)) # #par("mar") (bottom, left, top, right) for margin
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.