Skip to content

Commit

Permalink
add number of points to plot
Browse files Browse the repository at this point in the history
  • Loading branch information
hillalex committed Nov 18, 2024
1 parent b78e123 commit 2398227
Show file tree
Hide file tree
Showing 4 changed files with 1,512 additions and 1,105 deletions.
26 changes: 17 additions & 9 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,22 +153,30 @@ plot.biokinetics_individual_trajectories <- function(x, ..., data = NULL,
geom_ribbon(aes(x = calendar_day,
ymin = lo,
ymax = hi,
group = titre_type), alpha = 0.5) +
geom_smooth(
aes(x = calendar_day,
y = me,
fill = titre_type,
colour = titre_type,
group = titre_type),
alpha = 0.5, span = 0.2)
group = titre_type), alpha = 0.5)
} else {
x <- x[
!is.nan(mu), .(ind_mu_sum = mean(mu)),
by = c("calendar_day", "pid", "titre_type")]
count <- x[, .(count = data.table::uniqueN(pid)), by = .(calendar_day)]
plot <- ggplot(x) +
geom_line(aes(x = calendar_day, y = ind_mu_sum,
colour = titre_type, group = interaction(titre_type, pid)),
alpha = 0.5, linewidth = 0.1)
alpha = 0.5, linewidth = 0.1) +
geom_smooth(
aes(x = calendar_day,
y = ind_mu_sum,
fill = titre_type,
colour = titre_type,
group = titre_type),
alpha = 0.5, span = 0.2) +
scale_y_continuous(sec.axis = sec_axis(~., name = "Number of data points")) +
geom_bar(data = count, aes(x = calendar_day, y = count),
stat = "identity", alpha = 0.6) +
theme(axis.ticks.y.right = element_line(alpha = 0.6),
axis.text.y.right = element_text(alpha = 0.6),
axis.title.y.right = element_text(alpha = 0.6)
)
}
if (!is.null(data)) {
validate_required_cols(data, c("day", "value"))
Expand Down
Loading

0 comments on commit 2398227

Please sign in to comment.