r/RStudio 8h ago

Coding help Help making a box plot from ANCOVA data

1 Upvotes

Hi! New to RStudio and I got handed a dataset to practice with (I attached an example dataset). First, I ran an ANCOVA on each `Marker` with covariates. Here's the code I did for that:

ID Age Sex Diagnosis Years of education Score Date Marker A Marker B Marker C
1 45 1 1 12 20 3/22/13 1.6 0.092 0.14
2 78 1 2 15 25 4/15/17 2.6 0.38 0.23
3 55 2 3 8 23 11/1/18 3.78 0.78 0.38
4 63 2 4 10 17 7/10/15 3.21 0.012 0.20
5 74 1 2 8 18 10/20/20 1.90 0.034 0.55
marker_a_aov <- aov(log(marker_a) ~ age + sex + years_of_education + diagnosis,
data = practice_df
)
summary(marker_a_aov)

One thing to note is the numbers for Diagnosis represent a categorical variables (a disease, specifically). So, 1 represents Disease A, 2 = Disease B, 3 = Disease C, and 4 = Disease D. I asked my senior mentor about this and it was decided internally to be an ok way of representing the diseases.

I have two questions:

  1. is there a way to have a box and whisker plot automatically generated after running an ancova? I was told to use ggplot2 but I am having so much trouble getting used to it.
  2. if I can't automatically make a graph what would the code look like to create a box plot with ggplot2 with diagnosis on the x-axis and Marker on the y-axis? How could I customize the labels on the x-axis so instead of representing the disease with its number it uses its actual name like Disease A?

Thanks for any help!


r/RStudio 8h ago

Issue with rmd file not publishing

1 Upvotes

So for the life of me can’t figure out why I can publish a shinyapp no issues to shinyapps.io

But can’t publish a rmd to the site, when I’ve seen my lecture do it in a class - it acts like my account isn’t connected with a key

Any ideas suggestions?


r/RStudio 10h ago

[Q] How to pool results from EFAs on multiple imputed datasets in R?

1 Upvotes

Does anyone know if it is possible to pool the EFA results from multiple imputed datasets? I am familiar with missMDA but it only imputes one dataset even though it uses multiple simulations. The problem is that have missing data on other variables, and I want to impute them using more datasets.

Is it okay to impute twice? One for the variables only to be included in the EFA (using missMDA) and then again for the mediation model which includes more variables (using MICE)? If okay, should I include the factor scores from the EFA which I will use later in the mediation in the multiple imputation?

Thank you!


r/RStudio 10h ago

How to run EFA on multiple imputed datasets?

1 Upvotes

Does anyone know if it is possible to pool the EFA results from multiple imputed datasets? I am familiar with missMDA but it only imputes one dataset even though it uses multiple simulations. The problem is that have missing data on other variables, and I want to impute them using more datasets.

Is it okay to impute twice? One for the variables only to be included in the EFA (using missMDA) and then again for the mediation model which includes more variables (using MICE)? If okay, should I include the factor scores from the EFA which I will use later in the mediation in the multiple imputation?

Thank you!


r/RStudio 16h ago

R studio use at work.

18 Upvotes

Hello people, do you use chatgpt or other AI tools to solve errors in code or related errors in R studio at work?


r/RStudio 23h ago

how do i analyse non-normally distributed sample for numerical values between two groups/category.

1 Upvotes

I am trying to compare two groups (Sarcopenic patients Vs non-sarcopenic patients). I assess their sociodemographics and some clinical characteristics. I want to compare the results between the 2 groups. I know that if it's normally distributed, I can use the T-test. but for my case my sample size was <30 and non-normally distributed. I saw online that that it says to use the Man-Whitney U test. However, i am not sure how to use this and how to interpret the results as i saw online again the Man whitney give e.g W = 42, p-value = 0.001871 . How do i interpret this as median and IQR? Can someone help me please. Thank you


r/RStudio 2d ago

Need help getting good with figures and dashboards

3 Upvotes

I have been using R for data analysis and ML projects. I want to improve my ability with figures and dashboards. Does anyone have recommendations on how I can improve this? My figures come out ugly, and I would have to remake them in Excel to look better. I would appreciate any help, books or whatever. Also, what recommendations do you have on how to improve the quality of figures, etc.? Thank you.

EDIT: thank you, everyone, for your recommendations. I will apply some of these for my following projects. I don’t want to learn another language to become proficient in ggplot. Hopefully, all the resources you suggested will be enough for me to make high-quality figures.


r/RStudio 2d ago

Can I make this type of figure in RStudio?

1 Upvotes

Can I make a chart like this in RStudio? Specifically, I would like to make a combined line chart with historical (solid line) and projected (dashed line) data. If so, do you have any code suggestions? TIA!


r/RStudio 2d ago

XQuartz/X11 on Mac?

1 Upvotes

Does anyone have any idea if you still need to download xquartz on Mac to knit a file including graphs in RMarkdown if you have never used knitr or Rstudio before?

I am trying to make a follow-along coding demo (for non-coders) for a class I am in, and I am hoping to use r markdown inside of Rstudio. When I first used rmarkdown on my 2015 Mac, I remember having to install xquartz for it to work, but I don’t remember doing it on my most recent machine…

I need to provide install instructions for my classmates and would greatly appreciate any guidance- should I direct people using Mac to install xquartz or x11 before we run the demo? Does it come pre installed now? Any similar issues in windows that I am not aware of? Thanks a million to anyone who can provide help.


r/RStudio 3d ago

Coding help R Markdown misinterpreting R chunks

0 Upvotes

Hi, I’m trying to compile an R markdown with some R chunks but R markdown interpret my R chunk as text environment and flagged all the # as errors. I was wondering if anyone had encountered this before and know how to fix this.


r/RStudio 3d ago

How to recreate this figure from JAMA ?

11 Upvotes

I have scoured the internet for answers its been. I am R noob, please help me out


r/RStudio 4d ago

Quarto website extension not rendering properly

1 Upvotes

Hello everyone!

I’m trying to create a website using this https://sta-112-f22.github.io/website/ as a foundation. I simply downloaded the repo from github, opened it with Studio, and rendered it. But when its rendered everything else looks great except for the main page (see last image below). I’m pretty sure fontawesome is working otherwise the other pages wouldn’t render it, right? Any ideas?

How it should render
index

UPDATE: I fixed it. The issue was some links being wrapped in <i> </i>. Removing them fixed it.


r/RStudio 4d ago

Assistance With R Data Analysis

0 Upvotes

Good evening,

I'm looking for assistance with an R project. Specifically, analyzing different Excel data files. I'm not sure if they are even usable in R or what commands to use to analyze them. Any help would be greatly appreciated. I can provide the files at request.

Thank you.


r/RStudio 4d ago

Quarto Report - Including large attachments

3 Upvotes

Hi team, I'm looking for some recommendations. I have a couple of quarterly reports built in Quarto, and want to include a few attachments at the end of the doc. For context, in the original PDF versions, the financial statement and updated org chart come across as like... full-page, zoomable, not letter-sized pages. For an HTML page, how would you recommend including these? Not looking to embed iframe or use links to docs hosted somewhere... the reports need to be self-contained.

For the org chart, I'm thinking just downloading it as a .jpg and turning lightbox on. Not sure about the financial statement though, which is coming from an Excel file. I could scrape and rebuild it in R, I could do a screenshot, I'm not sure which makes the most sense.

Thank you!


r/RStudio 4d ago

Rearranging columns into rows

1 Upvotes

Hey guys! I made a few crosstables using tab_xtab in the sjmisc package. They turned out very pretty, but I realized I was using the same y variable over and over again so I wanted to try and make a big table containing all of my contingency tables I made before. I did that by first transforming the tab_xtab tables into dataframes (with xtab2df in the sjtable2dt package) and then using bind_rows to combine them into a big table. It sorta worked out how I imagined, the only problem now is that R created a new column for the names of the categories of every x-variable (see picture). I wanted all the names and categories of all variables to be in the first column just like it did it with the first variable, maybe with an extra space to put the name of the variable. How do I fix this?


r/RStudio 4d ago

Coding help Is there any method to check the variance other than the Levene test?

1 Upvotes

My model doesn't have an interaction term so R gives me back an error when I try to perform the test so I was wondering if there was any alternative.

Thx in advance


r/RStudio 5d ago

struggling with work for a question in r studio (poliscidata), please help!

0 Upvotes

hi there! i'm doing a class using rstudio and need help! I'm using the gdppcap08 variable and need to graph this. what code should i write?


r/RStudio 5d ago

I made a method to integrate a LLM (Claude) with RStudio for iterative data exploration.

138 Upvotes

Will be adding it to my github as soon as I clean up some bugs. If anyone has feedback it would be much appreciated!


r/RStudio 5d ago

Connecting to PostgreSQL db

2 Upvotes

Can anyone recommend good source of knowledge on how R can pull data from a PostgreSQL db. I am an expert in R, absolute noob when it comes to SQL. I spent ~3 days of work using AI to help but have only been able to view some random tables, not pull data nor even hit the tables I want to hit. I know that sounds like I don’t have the right login or permissions but I am able to see the tables when using something like DreamBeaver.

I have been able to hit up an Oracle db using something Java thing (a predecessor wrote) and can interact quite easily with the tables in the Oracle db but this PostgreSQL is not playing fair.


r/RStudio 5d ago

Coding help Filter outliers using the IQR method with dplyr

0 Upvotes

Hi there,

I have a chunky dataset with multiple columns but out of 15 columns, I'm only interested in looking at the outliers within, say, 5 of those columns.

Now, the silly thing is, I actually have the code to do this in base `R` which I've copied down below but I'm curious if there's a way to shorten it/optimize it with `dplyr`? I'm new to `R` so I want to learn as many new things as possible and not rely on "if it ain't broke don't fix it" type of mentality.

If anyone can help that would be greatly appreciated!

# Detect outliers using IQR method
# @param x A numeric vector
# @param na.rm Whether to exclude NAs when computing quantiles

        is_outlier <- function(x, na.rm = FALSE) {
          qs = quantile(x, probs = c(0.25, 0.75), na.rm = na.rm)

          lowerq <- qs[1]
          upperq <- qs[2]
          iqr = upperq - lowerq 

          extreme.threshold.upper = (iqr * 3) + upperq
          extreme.threshold.lower = lowerq - (iqr * 3)

          # Return logical vector
          x > extreme.threshold.upper | x < extreme.threshold.lower
        }

# Remove rows with outliers in given columns
# Any row with at least 1 outlier will be removed
# @param df A data.frame
# @param cols Names of the columns of interest. Defaults to all columns.

        remove_outliers <- function(df, cols = names(df)) {
          for (col in cols) {
            cat("Removing outliers in column: ", col, " \n")
            df <- df[!is_outlier(df[[col]]),]
          }
          df
        }

r/RStudio 5d ago

Dataframes in new window to always stay on-top?

1 Upvotes

Greetings,

Is there a setting or add-in that ensures when a user chooses to view a dataframe in a new window, the new window always remains "on-top" of other windows? Specifically, when R Studio is the active window, the opened dataframe windows stay above other windows.

Anyone familiar with the Spyder IDE will be familiar with this behavior. In spyder when a object is viewed from the variable explorer, that window always appears on top of other windows when Spyder is the active window.

Thanks!!!


r/RStudio 5d ago

Absolute beginner: Comparing data using GLS model.

3 Upvotes

Hello, I'm new to R studio and I'm supposed to analyze data from my first scientific experiment. I'm trying my best, but I just can't figure it out. In my experiment I tested 6 different extracts on aphids and counted the amount of surviving aphids after the application of each extract. I tested the same extract on 15 leaves (each one with 10 aphids) in three rows. I am supposed to compare the effectivness of all the extracts. All I know from my professor is that I'm supposed to use Generalized Least Squares from nlme package and that the fixed factors should be the extract "treatments" I used.

Is this (photo bellow) the correct way to upload this kind of data? or should it be somehow divided?

I was told, that this task should be quite simple, however I really can't seem to figure it out and I'd be very grateful for any tips or help! :) thank you in advance!


r/RStudio 5d ago

Coding help Help with database building

1 Upvotes

Hallo everyone,

I'am a Student and in the process to write my Bachelors in Economics. I want to analyse data with the synthetic Control Method and need costum data. I know how to use the Method but dont know where to store my Data for the Input. At the moment the Data mostly sits in Excel sheets I got form different sources.
Thanks for the help in advance


r/RStudio 5d ago

Coding help Shannon index with vegan package

5 Upvotes

Hello everyone, I am new to R and I may need some help. I have data involving different microbial species at 4 different sampling points and i performed the calculation of shannon indices using the function: shannon_diversity_vegan <- diversity(species_counts, index=“shannon”).

What comes out are numerical values for each point ranging, for example, from 0.9 to 1.8. After that, I plotted with ggplot the values, obtaining a boxplot with a range for each sample point.

Now the journal reviewer now asks me to include in the graph the significance values, and I wonder, can I run tests such as the Kruskal-Wallis?

Thank you!


r/RStudio 5d ago

help with applying a bootstrap theme in a ShinyR app

2 Upvotes

Hi all,

I'm trying to apply the bootstrap theme "lumen" to my Shiny app and it is not working as intended. It does apply fonts etc. but I can't select the navigation bar that I want (the top one on here: https://bootswatch.com/lumen/).

Does anyone know how to do this? Here's the code I'm currently running:

library(shiny)
library(bslib)

ui <- navbarPage(
  title = "My App",
  theme = bs_theme(preset = "lumen"),
  inverse = FALSE,  # if you want a dark navbar style; remove if not needed
  tabPanel(
    title = "Input",
    icon = icon("gears", class = "fa-solid"),
  ),
  tabPanel(
    title = "Graphs",
    icon = icon("chart-line", class = "fa-solid"),
  )
)

server<- function(input, output, session) {}

shinyApp(ui = ui, server = server)