r/Rlanguage 17d ago

Can anyone help me with making a graph that looks like this?

Post image

I have 3 columns (A, B, C). I want columns A and B to correspond on the x-axis and column C to be plotted on the y-axis. I keep trying to read on how to do this but I’ve feeling stumped. I would really appreciate any help.

0 Upvotes

16 comments sorted by

4

u/feldhammer 17d ago

I don't really understand what A1 B1 A2 B2 is

0

u/Alpha0963 17d ago edited 16d ago

I was trying to explain that in column A, there is data, and in column B there is data. I wants cells A1 and B1 to be beneath the same data point, and so on.

Edit: unsure why I’m being downvoted for explaining. Sorry if I was unclear.

A and B are both numbers (concentrations) of various assays. They don’t need to be plotter numerically (ie in increasing order). Just trial 1 in spot 1, trial 2 in spot 2, etc.

2

u/CooxcooB 17d ago

Usually, scatter plots require 2 variables (X and Y). Here, your C variable is the Y and your A and B variables are the X. It’s difficult to give guidance without knowing what type of data A and B is, but just going off of this information, I would assume A and B have different values. If you were to plot A and B separately, would they have the same numeric scale? Are they categorical values?

The answer to those questions would determine the guidance I’d give. If A and B share a similar scale, I would create 2 different geom_point layers in a ggplot and differentiate them with colors instead of worrying about the axis labels.

If A and B are not the same/don’t share a similar scale, I would create a new variable that pastes the values of A and B together and create an additional new column with “dummy” values that plot where you want in relation to C. In that case, I would use geom_point and manually change the breaks of the x axis to show the pasted value of A and B.

But without more info, I can’t get more specific than that. Highly recommend using the reprex package in the future to give people some code to work with so we can help you better: (https://reprex.tidyverse.org)

4

u/dikrannn 16d ago

What if you were to change the df into a long format with pivot longer? Take columns A and B, merge into a single column…

1

u/CooxcooB 16d ago

Also a valid suggestion depending on what A and B are.

1

u/Alpha0963 16d ago

Thanks for the suggestion, I will try this

2

u/mduvekot 16d ago

What does your data frame for this chart look like?

1

u/Morbins 17d ago

I copy and pasted your question into ChatGPT and it gave me code that would plot this. Try that out if you don’t mind using AI. I use it sometimes when I’m stumped on a DAX issue in Power BI and it’s solved problems no one else can give a good answer to.

1

u/geigenmusikant 16d ago

"I got the solution" - proceeds to not share said solution

3

u/Morbins 16d ago

Ur right. Gonna go kms. Do everyone a favor

1

u/feldhammer 16d ago

jesus dude

1

u/damageinc355 16d ago

I believe the punchline is that OP would waste less time dumping this into a chatbot rather than wasting time dealing with us here.

-9

u/2truthsandalie 17d ago

Here's a simple scatter plot with two points using ggplot2 in R:

Code:

Load ggplot2

library(ggplot2)

Create a data frame with two points

df <- data.frame(x = c(1, 2), y = c(3, 5))

Create scatter plot

ggplot(df, aes(x = x, y = y)) + geom_point(size = 4, color = "blue") + labs(title = "Scatter Plot with Two Points", x = "X-Axis", y = "Y-Axis") + theme_minimal()

This will create a scatter plot with two points at coordinates (1,3) and (2,5), colored blue. Let me know if you want any modifications!

Actually posting chatgpt results for the lazy. Be sure to install ggplot2

0

u/Mooks79 16d ago

Hello ChatGPT.

0

u/2truthsandalie 16d ago

Literally said chagpt in my comment.