Error in `dplyr::mutate()`
1
0
Entering edit mode
18 months ago
shamza • 0

Hey all, I am trying to run this script in R but due to some reason I am getting the following error, I don't know what I am missing. Any help would be appreciated.

library("tidyverse")
library("ggrepel")
library("dplyr")

df |>
  dplyr::mutate(
    label=ifelse(
      avg_log2FC >= nth(avg_log2FC, 10, desc(avg_log2FC)) | avg_logFC <= nth(avg_log2FC, 10, avg_log2FC),
      Gene, NA),
    DEGs=dense_rank(-avg_log2FC)) |>
  ggplot(aes(x=DEGs, y=avg_log2FC)) +
  geom_point(aes(color=avg_log2FC), show.legend=FALSE) +
  geom_text_repel(aes(label=label)) +
  geom_hline(yintercept=0, linetype="dashed")

I am trying to construct a visualization, a p-fold plot. This is what my df looks like and the plot I want to construct

gene         p_val avg_log2FC pct.1 pct.2     p_val_adj
RPS12         RPS12 1.806317e-144  0.7350248 1.000 0.991 2.477183e-140
RPS6           RPS6 7.135900e-142  0.6798622 1.000 0.995 9.786173e-138
RPS27         RPS27 5.257820e-140  0.7207819 0.999 0.992 7.210575e-136
RPL32         RPL32 4.229582e-136  0.6115515 0.999 0.995 5.800448e-132
RPS14         RPS14 1.799019e-130  0.6199183 1.000 0.994 2.467175e-126
RPS25         RPS25 5.507298e-123  0.7442491 0.997 0.975 7.552709e-119
RPS3           RPS3 1.412450e-117  0.6094866 1.000 0.994 1.937034e-113
RPL9           RPL9 3.657623e-117  0.7443112 0.994 0.971 5.016065e-113
RPL13         RPL13 7.368767e-117  0.5651751 1.000 0.996 1.010553e-112
RPL31         RPL31 2.746961e-116  0.7396594 0.996 0.964 3.767182e-112
RPL3           RPL3 6.398782e-113  0.6090295 0.997 0.995 8.775289e-109
RPL21         RPL21 3.609756e-111  0.6704414 0.997 0.991 4.950419e-107

enter image description here

Error in `dplyr::mutate()`:
  In argument: `label = ifelse(...)`.
Caused by error:
! unable to find an inherited method for function 'desc' for signature '"numeric"'
Run `rlang::last_trace()` to see where the error occurred.
R dplyr • 3.6k views
ADD COMMENT
1
Entering edit mode
18 months ago

R might be using the wrong desc function. Try replacing it with dplyr::desc to explicitly call the function from the dplyr library.

ADD COMMENT
0
Entering edit mode

it worked, Thank you!

ADD REPLY
0
Entering edit mode

Can you provide the code to get similar color plot? Thank you

ADD REPLY

Login before adding your answer.

Traffic: 2768 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6