Colleagues, I am trying to plot a simple line using ggplot2. I get the axes, but I don't get the line. Please let me know what my error I am making. Thank you, John # Define x and y values PointEstx <- Estx+1.96*SE PointEsty <- 1 row2 <- cbind(PointEstx,PointEsty) linedata<- data_frame(rbind(row1,row2)) linedata # make sure we have a data frame class(linedata) #plot the data ggplot(linedata,aes(x=PointEstx, y=PointEsty), geom_line())
Please run your code before you send it. Your example is not reproducible. library(ggplot2) linedata<- data.frame( PointEstx = c( 1, 2 ) , PointEsty = c( 1, 1.5 ) ) # make sure we have a data frame str(linedata) #plot the data ggplot( linedata , aes( x = PointEstx , y = PointEsty ) ) + geom_line() On December 8, 2022 5:05:47 PM PST, "Sorkin, John" <jsorkin at som.umaryland.edu> wrote:>Colleagues, > >I am trying to plot a simple line using ggplot2. I get the axes, but I don't get the line. Please let me know what my error I am making. >Thank you, >John > ># Define x and y values >PointEstx <- Estx+1.96*SE >PointEsty <- 1 > >row2 <- cbind(PointEstx,PointEsty) >linedata<- data_frame(rbind(row1,row2)) >linedata ># make sure we have a data frame >class(linedata) > >#plot the data >ggplot(linedata,aes(x=PointEstx, y=PointEsty), geom_line()) > > > > > >______________________________________________ >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.-- Sent from my phone. Please excuse my brevity.
A number of problems. The variable names are not helpful. PointEstx is not a point it is a value. I need an x and a y coordinate for a point. row1 is not defined While there is a function data.frame(), there is no data_frame(). Making this change gives an error that row1 is not defined. I solved the problem with row1<-row2+1. The ggplot statement looks wrong. Does this give you what you need? ggplot(linedata,aes(x=PointEstx, y=PointEsty)) + geom_line() Note I changed the comma to a plus sign and changed the brackets. Regards, Tim -----Original Message----- From: R-help <r-help-bounces at r-project.org> On Behalf Of Sorkin, John Sent: Thursday, December 8, 2022 8:06 PM To: r-help at r-project.org (r-help at r-project.org) <r-help at r-project.org> Subject: [R] Plot a line using ggplot2 [External Email] Colleagues, I am trying to plot a simple line using ggplot2. I get the axes, but I don't get the line. Please let me know what my error I am making. Thank you, John # Define x and y values PointEstx <- Estx+1.96*SE PointEsty <- 1 row2 <- cbind(PointEstx,PointEsty) linedata<- data_frame(rbind(row1,row2)) linedata # make sure we have a data frame class(linedata) #plot the data ggplot(linedata,aes(x=PointEstx, y=PointEsty), geom_line()) ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C01%7Ctebert%40ufl.edu%7C5695e850b24347d9fcf908dad9818f28%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C638061447740857132%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=KhRB4ZHKsoVlPRsAnufXXzfiJyRBEEv32P7bcAAiGBo%3D&reserved=0 PLEASE do read the posting guide https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=05%7C01%7Ctebert%40ufl.edu%7C5695e850b24347d9fcf908dad9818f28%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C638061447740857132%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=DPlvmxCIwlF1WqKWawzSmJbosiFGjnLwFIMKK7hFAco%3D&reserved=0 and provide commented, minimal, self-contained, reproducible code.