How to create 4x4 scatter plot using GGPLOT Facet
By : Ashutosh Kumar Singh
Date : March 29 2020, 07:55 AM
I wish this helpful for you I have data frame like this: code :
library(ggplot2)
d.405 <- data.frame(abs(rnorm(30)),abs(rnorm(30)),abs(rnorm(30)),abs(rnorm(30)),type="405")
d.409 <- data.frame(abs(rnorm(30)),abs(rnorm(30)),abs(rnorm(30)),abs(rnorm(30)),type="409")
all <- rbind(d.405,d.409)
colnames(all) <- c("401","402","403","404","type")
library("reshape2");
allM <- melt(all, id.vars = "type")
combis <- expand.grid(levels(allM$variable),levels(allM$variable))
plotdat <- lapply(seq_len(nrow(combis)),function(i) cbind(allM[allM$variable==combis[i,1] & allM$type=="405",],
allM[allM$variable==combis[i,2] & allM$type=="409",c("type","variable","value")]))
plotdat <- do.call(rbind,plotdat)
names(plotdat) <- c("type.x","var.x","x","type.y","var.y","y")
plotdat$var.x <- paste("x:",plotdat$var.x)
plotdat$var.y <- paste("y:",plotdat$var.y)
library(plyr)
cors <- ddply(plotdat,.(var.x,var.y),summarize,cor=format(signif(cor(x,y),2),scientific=-2))
cors$x <- 2.2
cors$y <- 2.5
p <- ggplot(plotdat,aes(x=x,y=y)) +
geom_point() +
geom_smooth(method="lm") +
geom_text(data=cors,aes(label=paste("r =",cor))) +
facet_wrap(~var.y*var.x,ncol=4) +
xlab("405") + ylab("409")
print(p)
|
GGplot does not change color of scatter plot but does on other plots
By : Raffy
Date : March 29 2020, 07:55 AM
hope this fix your issue in this line geom_point(aes(colour=ifelse( data3$LOF>lof & data3$Z_LAST_DAYS 100,"#8e8f90","#f40009")), size = 3) code :
ggplot(iris, aes(Sepal.Width, Sepal.Length)) +
geom_point(aes(colour="pink"))
ggplot(iris, aes(Sepal.Width, Sepal.Length)) +
geom_point(colour="pink")
geom_point(colour=ifelse( data3$LOF>lof & data3$Z_LAST_DAYS<days & data3$CE11000_ERLOS>100,"#8e8f90","#f40009"), size = 3)
|
ggExtra plot format: similar marginal plots for different plot dimensions
By : Sachin Gupta
Date : March 29 2020, 07:55 AM
|
Marginal plots using axis_canvas in cowplot: How to insert gap between main panel and marginal plots
By : A. Varukhin
Date : March 29 2020, 07:55 AM
it should still fix some issue The following came up in a comment to this post: When making marginal plots with the axis_canvas() function in cowplot, how can we create a gap between the main plot and the marginal plot? , I see two options: Insert empty plot code :
# pmain, xbox, ybox are defined as in the question
pnull <- ggdraw() # generate empty plot
p1 <- insert_xaxis_grob(
insert_xaxis_grob(pmain, xbox, grid::unit(0.6, "in"), position = "top"),
pnull, grid::unit(0.2, "in"), position = "top")
p2 <- insert_yaxis_grob(
insert_yaxis_grob(p1, ybox, grid::unit(0.6, "in"), position = "right"),
pnull, grid::unit(0.2, "in"), position = "right")
ggdraw(p2)
xbox2 <- axis_canvas(pmain, axis = "x", coord_flip = TRUE) +
geom_boxplot(data = mpg, aes(y = cty, x = as.numeric(factor(cyl)), color = factor(cyl))) +
scale_x_continuous(limits = c(-2, 4.5)) + coord_flip()
ybox2 <- axis_canvas(pmain, axis = "y") +
geom_boxplot(data = mpg, aes(y = hwy, x = as.numeric(factor(cyl)), color = factor(cyl))) +
scale_x_continuous(limits = c(-2, 4.5))
p1 <- insert_xaxis_grob(pmain, xbox2, grid::unit(0.8, "in"), position = "top")
p2 <- insert_yaxis_grob(p1, ybox2, grid::unit(0.8, "in"), position = "right")
ggdraw(p2)
plot_grid(xbox + panel_border("black"),
xbox2 + panel_border("black"), nrow = 1, scale = 0.9)
|
How to create two lines and scatter plots using ggplot
By : user1128882
Date : March 29 2020, 07:55 AM
Does that help I have the following data in R: , How about something like this? code :
data %>%
gather(k, value, -id) %>%
mutate(
state = gsub("(\\.e$|\\.f$)", "", k),
what = gsub("(initial\\.|final\\.)", "", k)) %>%
ggplot(aes(id, value, colour = what)) +
geom_line() +
facet_wrap(~ state)
data %>%
gather(k, value, -id) %>%
mutate(
state = gsub("(\\.e$|\\.f$)", "", k),
what = gsub("(initial\\.|final\\.)", "", k)) %>%
ggplot(aes(id, value, colour = what)) +
geom_line() +
geom_point() +
facet_wrap(~ state)
data %>%
gather(k, value, -id) %>%
mutate(
state = gsub("(\\.e$|\\.f$)", "", k),
what = gsub("(initial\\.|final\\.)", "", k)) %>%
select(-k) %>%
spread(state, value) %>%
ggplot(aes(x = initial, y = final, colour = what, fill = what)) +
geom_smooth(fullrange = T, method = "lm") +
geom_point()
|