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

add label option on line.R #32

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Authors@R: c(
person("Changwoo", "Lim", email = "limcw@zarathu.com", role = c("aut")),
person("Jinhwan", "Kim", email = "jinhwan@zarathu.com", role = c("aut"), comment = c(ORCID = "0009-0009-3217-2417")),
person("Yoonkyoung", "Jeon", email = "rachel200357@gmail.com", role = c("aut")),
person("Jaewoong", "Heo", email = "koolerjaebee@gmail.com", role = c("aut")))
person("Jaewoong", "Heo", email = "koolerjaebee@gmail.com", role = c("aut")),
person("Youngsun", "Park", email = "ddspys@gmail.com", role = c("aut"), comment = c(ORCID = "0009-0009-9336-2281")))
Description: 'RStudio' addins and 'Shiny' modules for descriptive statistics, regression and survival analysis.
Depends: R (>= 3.4.0)
License: Apache License 2.0
Expand Down Expand Up @@ -52,7 +53,8 @@ Imports:
survIDINRI,
survival,
timeROC,
utils
utils,
ggrepel
URL: https://jinseob2kim.github.io/jsmodule/, https://github.com/jinseob2kim/jsmodule
BugReports: https://github.com/jinseob2kim/jsmodule/issues
Suggests:
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export(timerocModule2)
export(timerocUI)
import(flextable)
import(ggplot2)
import(ggrepel)
import(shiny)
importFrom(DT,"%>%")
importFrom(DT,DTOutput)
Expand Down
38 changes: 33 additions & 5 deletions R/line.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ lineUI <- function(id, label = "lineplot") {
checkboxInput(ns("linetype"), "Linetype"),
checkboxInput(ns("jitter"), "Jitter"),
checkboxInput(ns("rev_y"), "Reverse Y-axis"),
checkboxInput(ns("label"), "Label"),
uiOutput(ns("pvalue")),
uiOutput(ns("subvar")),
uiOutput(ns("subval")),
uiOutput(ns("subval"))

# uiOutput(ns("size")),
# uiOutput(ns("position.dodge"))
)
Expand Down Expand Up @@ -112,6 +114,7 @@ lineUI <- function(id, label = "lineplot") {
#' @rdname lineServer
#' @export
#' @import shiny
#' @importFrom ggrepel geom_text_repel geom_label_repel
#' @importFrom data.table data.table .SD :=
#' @importFrom ggpubr ggline stat_compare_means geom_pwc
#' @importFrom ggplot2 ggsave scale_y_reverse
Expand Down Expand Up @@ -361,7 +364,7 @@ lineServer <- function(id, data, data_label, data_varStruct = NULL, nfactor.limi
})

lineInput <- reactive({
req(c(input$x_line, input$y_line, input$strata, input$pvalfont, input$s_pvalue, input$positiondodge))
req(c(input$x_line, input$y_line, input$strata, input$pvalfont, input$s_pvalue, input$positiondodge, input$label))
req(input$isStrata != "None")

data <- data.table(data())
Expand All @@ -373,9 +376,9 @@ lineServer <- function(id, data, data_label, data_varStruct = NULL, nfactor.limi
)
if (input$jitter) {
add <- switch(input$options,
"Mean_SE" = c("jitter", "mean_se"),
"Mean_SD" = c("jitter", "mean_sd"),
"Median_IQR" = c("jitter", "median_iqr")
"Mean_SE" = c("mean_se", "jitter"),
"Mean_SD" = c("mean_sd" , "jitter"),
"Median_IQR" = c("median_iqr", "jitter")
)
}

Expand Down Expand Up @@ -411,6 +414,7 @@ lineServer <- function(id, data, data_label, data_varStruct = NULL, nfactor.limi
size = line.size,
point.size = line.point.size,
linetype = linetype

)

if (input$rev_y) {
Expand All @@ -429,6 +433,30 @@ lineServer <- function(id, data, data_label, data_varStruct = NULL, nfactor.limi
)
}

if (input$label) {




if(con3 <- input$strata != "None"){
res.plot <- res.plot +
ggplot2::stat_summary(fun.data = function(x){
return(data.frame(y = mean(x), label = round(mean(x), 2))) },
geom = "label",
aes(label = !!sym(input$y_line),
group = !!sym(input$strata)))
}else{
res.plot <- res.plot +
ggplot2::stat_summary(fun.data = function(x){
return(data.frame(y = mean(x), label = round(do.call(add[1],list(x = x))[[1]], 2))) },
geom = "label",
aes(label = !!sym(input$y_line),
))
}

}


return(res.plot)
})

Expand Down
Loading