Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ggplot2 R error #2

Closed
jpincru opened this issue Oct 23, 2020 · 1 comment
Closed

ggplot2 R error #2

jpincru opened this issue Oct 23, 2020 · 1 comment
Assignees

Comments

@jpincru
Copy link
Collaborator

jpincru commented Oct 23, 2020

Al generar los gráficos salta error, he probado a utilizar el .csv tanto con el paso de interpolación como sin él por si fuera la causa pero el error es el mismo.

Moving Average Smoothing parameters

MA_order <- 12

Dataframe reordering for facet plotting

df_MA <- data.frame(apply(df[,c("vt","convexity", "circularity", "major","minor")], 2, SMA, n=MA_order))
df_MA <- df_MA %>% mutate_all(funs((. - min(., na.rm = T))/(max(., na.rm = T) - min(., na.rm = T))))
df_MA_long <- melt(df_MA)
Time = rep(1:181, 5)

Plot generation

Time series trajectory

p1 <- ggplot(df, aes(x=frame, y=y)) +
geom_line() +
xlab("") +
ylab("Position (microns)") +
theme_bw() +
geom_vline(xintercept = c(best.case$end, best.case$begin),
color = "black", size=0.5)

Moving average values of each morphological descriptor and velocity

p2 <- ggplot(data=df_MA_long, aes(x=Time, y=1, fill=value, color=variable)) +
facet_wrap(~variable, ncol=1, scales='free') +
scale_fill_gradientn(colours=c("#15BFC3", "#FC367A", "white", "gray"),
na.value = "transparent",
breaks=c(0,0.5,1),labels=c(0,0.5,1),
limits=c(0,1)) +
theme_bw() +
ylab('') +
geom_raster() +
labs(fill = "Relative\nvalue") +
theme(axis.text.y=element_blank(),axis.ticks.y=element_blank()) +
geom_vline(xintercept = c(best.case$end, best.case$begin),
color = "black", size=0.5)

Arranging the plots in the same column for better visualization, using egg library.

ggarrange(p1,p2, ncol = 1,heights = c(2, 4))

Error: Aesthetics must be either length 1 or the same as the data (900): x
Traceback:

  1. ggarrange(p1, p2, ncol = 1, heights = c(2, 4))
  2. lapply(plots, ggplot2::ggplotGrob)
  3. FUN(X[[i]], ...)
  4. ggplot_gtable(ggplot_build(x))
  5. ggplot_build(x)
  6. ggplot_build.ggplot(x)
  7. by_layer(function(l, d) l$compute_aesthetics(d, plot))
  8. f(l = layers[[i]], d = data[[i]])
  9. l$compute_aesthetics(d, plot)
  10. f(..., self = self)
  11. check_aesthetics(evaled, n)
  12. abort(glue("Aesthetics must be either length 1 or the same as the data ({n}): ",
    . glue_collapse(names(which(!good)), ", ", last = " and ")))
  13. signal_abort(cnd)
@danilexn danilexn self-assigned this Oct 23, 2020
@danilexn
Copy link
Owner

Fixed in 168990a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants