I have a ggplot2 which has x-values 0-200 and y values 0-10 p=plot(mydata) p+xlim(0, 200) I want to show what is the y value when we have 75 as x value. The graph which is displayed has a broad range (like 0-50, 50-100 etc on x axis) and cannot determine the exact value of y at the value of 75 on x-axis. Thank you [[alternative HTML version deleted]]
What exactly do you want to show Neha? First, I am not clear on how you use plot() rather than ggplot() in your example and do not?bind what x and y are in an aesthetic and more. So I suspect you are again giving an incomplete example. So what do you want in any case? Do you want to add say a horizontal or vertical line drawn at?one or more points such as a vertical line at x=75 that intersects the graph, or a horizontal line for?y at f(75) as one example. Do you want a special dot of another color or some text near there specifying the number? Or do?you want toi change the breaks on the scale of the x axis to include a "75" or make more of them?closer together or ... ??? You can do many such things easily enough but unless you specify what you want, no point in?answering. -----Original Message----- From: Neha gupta <neha.bologna90 at gmail.com> To: r-help mailing list <r-help at r-project.org> Sent: Thu, May 26, 2022 7:40 pm Subject: [R] How to show a specific value of a ggplot2 I have a ggplot2 which has x-values 0-200 and y values 0-10 p=plot(mydata) p+xlim(0, 200) I want to show what is the y value when we have 75 as x value. The graph which is displayed has a broad range (like 0-50, 50-100 etc on x axis) and cannot determine the exact value of y at the value of 75 on x-axis. Thank you ??? [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]]
Hello, If you cannot determine the exact value of y for given x, then isn't your problem how to determine an approximate value of y? Once you have it, it's easy to plot it. With newdata = data.frame(x = 75, y = ???), ggplot(mydata, mapping = aes(x, y)) + geom_point(color = "black") + geom_point(newdata, mapping = aes(x, y), color = "red") + xlim(0, 200) The question is how to find newdata$y, interpolation, other method? Hope this helps, Rui Barradas ?s 00:40 de 27/05/2022, Neha gupta escreveu:> I have a ggplot2 which has x-values 0-200 and y values 0-10 > > p=plot(mydata) > p+xlim(0, 200) > > I want to show what is the y value when we have 75 as x value. The graph > which is displayed has a broad range (like 0-50, 50-100 etc on x axis) and > cannot determine the exact value of y at the value of 75 on x-axis. > > Thank you > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.