Skip to content

Commit

Permalink
Update plot.n_factors.R
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil committed Apr 27, 2024
1 parent 6a646ac commit 96cabab
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions R/plot.n_factors.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,25 @@ plot.see_n_factors <- function(x,

# Base plot
if (type == "area") {
segment_data <- data.frame(x_intercept = x$x[which.max(x$y)], y_max = max(x$y, na.rm = TRUE))
p <- ggplot(x, aes(x = .data$x, y = .data$y)) +
geom_area(fill = flat_colors("grey")) +
geom_segment(
data = segment_data,
aes(
x = .data$x[which.max(.data$y)],
xend = .data$x[which.max(.data$y)],
x = x_intercept,
xend = x_intercept,
y = 0,
yend = max(.data$y)
yend = y_max
),
color = flat_colors("red")
) +
geom_point(aes(x = .data$x[which.max(.data$y)], y = max(.data$y)),
geom_point(
data = segment_data,
aes(x = x_intercept, y = y_max),
color = flat_colors("red")
) +
scale_x_continuous(breaks = 1:max(x$x)) +
scale_x_continuous(breaks = 1:max(x$x, na.rm = TRUE)) +
add_plot_attributes(x)
} else if (type == "line") {
p <- ggplot(x, aes(y = .data$x, x = .data$y, colour = .data$group)) +
Expand Down

0 comments on commit 96cabab

Please sign in to comment.