ggplot2 without points in the graphics.

Hi
Can someone help me?
I did a ggplot2. But there are no points, only x and y labs. I did this code:
library (ggplot2)
scatter<-ggplot(runners, aes("ventraleK","Fragebogen"))
scatter+geom_point()+ labs(x= "ventraleK", y= "Fragebogen")
scatter+geom_point()+ geom_smooth(method = "lm", colour= "Red", alpha =0.1, fill= "Blue")+
labs(x= "ventraleK", y= "Fragebogen")

scatter+geom_point()+ geom_smooth(method = "lm",aes(fill= Beschwerden), colour= "Red", alpha =0.1, fill= "Blue")+
labs(x= "ventraleK", y= "Fragebogen", colour= "Beschwerden")
scatter1<- ggplot(runners, aes("ventraleK", "Fragebogen", color = Beschwerden)) +
geom_point()+
facet_wrap(~Beschwerden)

Thanks
Rebecca

It looks like you have code there for a few different graphs. What happens if you run just this much code:

scatter<-ggplot(runners, aes("ventraleK","Fragebogen"))
scatter+geom_point()+ labs(x= "ventraleK", y= "Fragebogen")

Most often, aes() expects what's called bare variable names; i.e., variable names without quotes around them. Try removing the quotes in aes("ventraleK","Fragebogen").

Your code would then look something like aes(ventraleK, Fragebogen).

2 Likes

thanks a lot for your answer. Unfortunately it does not work.

My plot looks like this: image

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

thanks for your answer. I don't understand it. Can you send me the code?

What does your data look like? As suggested, can you provide some reproducible code?

runners <- read.table("runners.txt",sep = "\t",header = TRUE)
str(runners)
cor(runners)
pairs(~ventraleK+dorsaleK+lat.Krechts+lat.Klinks+Fragebogen+Frage1+Frage2+Frage3+Frage4+HuefteR+HuefteL+Balancerechts+Balancelinks+Beschwerden+Alter+BMI+Geschlecht+Leistungsniveau+Trainingsumfang, data=runners,main="Basic Scatter Plot Matrix")
library (corrgram)
corrgram(runners,order=TRUE, upper.panel=panel.ellipse,lower.panel=panel.conf,text.panel=panel.txt, main="Correlation Matrix runner")
library (ggplot2)
scatter<-ggplot(runners, aes("ventraleK","Fragebogen"))
scatter+geom_point()+ labs(x= "ventraleK", y= "Fragebogen")
scatter+geom_point()+ geom_smooth(method = "lm", colour= "Red", alpha =0.1, fill= "Blue")+
labs(x= "ventraleK", y= "Fragebogen")
#evtl. für Beschwerde-seite als Faktor

scatter+geom_point()+ geom_smooth(method = "lm",aes(fill= Beschwerden), colour= "Red", alpha =0.1, fill= "Blue")+
labs(x= "ventraleK", y= "Fragebogen", colour= "Beschwerden")#DK ist numerisch, Gender wäre eine Möglichkeit.

scatter1<- ggplot(runners, aes("ventraleK", "Fragebogen", color = Beschwerden)) +
geom_point()+
facet_wrap(~Beschwerden)

We don't have the runners.txt so don't have the data.

Can you provide a reproducible code? Something like shown here:
https://reprex.tidyverse.org/articles/articles/datapasta-reprex.html

I don't understand what i have to do. but someone has told me there is something wrong with the graphics. can you text me, how can i change the graphics?

Can you paste the output from dput(head(runners)) here? Then we can see the data and try out your code.

like this?
structure(list(Probanden = 1:6, ventraleK = c(57L, 105L, 46L,
97L, 52L, 118L), dorsaleK = c(60L, 80L, 80L, 59L, 79L, 56L),
lat.Krechts = c(60L, 44L, 61L, 56L, 56L, 7L), lat.Klinks = c(68L,
25L, 39L, 63L, 56L, 25L), Fragebogen = c(4, 0, 10, 1, 19.5,
0), Frage1 = c(2, 0, 0, 1, 7.5, 0), Frage2 = c(2, 0, 2, 0,
7.5, 0), Frage3 = c(0, 0, 5, 0, 4.5, 0), Frage4 = c(0, 0,
3, 0, 0, 0), HuefteR = c(1.16, 1.01, 1.28, 0.79, 1.42, 1.15
), HuefteL = c(1.16, 0.84, 1.46, 0.79, 0.99, 1.15), Balancerechts = c(90.58,
86.27, 74, 104.65, 91.12, 124.21), Balancelinks = c(87.45,
91.5, 78.87, 102.71, 87.87, 111.8), Beschwerden = structure(c(3L,
3L, 3L, 2L, 1L, 2L), .Label = c("links", "No", "rechts"), class = "factor"),
Alter = c(60L, 58L, 48L, 27L, 47L, 37L), BMI = c(18.78, 21.8,
21.15, 20.57, 19.14, 22.09), Geschlecht = structure(c(1L,
1L, 2L, 2L, 1L, 1L), .Label = c("M", "W"), class = "factor"),
X = c(NA, NA, NA, NA, NA, NA), Leistungsniveau = c(3L, 6L,
5L, 9L, 7L, 2L), Trainingsumfang = c(12, 18, 18, 10.05, 14.5,
19)), row.names = c(NA, 6L), class = "data.frame")

1 Like

If you remove the quotation marks from around the column names in the call to aes(), you can get a plot. This solution was mentioned by aosmith in the third post of this thread.

runners <- structure(list(Probanden = 1:6, ventraleK = c(57L, 105L, 46L,
                                                    97L, 52L, 118L), dorsaleK = c(60L, 80L, 80L, 59L, 79L, 56L),
                     lat.Krechts = c(60L, 44L, 61L, 56L, 56L, 7L), lat.Klinks = c(68L,
                                                                                  25L, 39L, 63L, 56L, 25L), Fragebogen = c(4, 0, 10, 1, 19.5,
                                                                                                                           0), Frage1 = c(2, 0, 0, 1, 7.5, 0), Frage2 = c(2, 0, 2, 0,
                                                                                                                                                                          7.5, 0), Frage3 = c(0, 0, 5, 0, 4.5, 0), Frage4 = c(0, 0,
                                                                                                                                                                                                                              3, 0, 0, 0), HuefteR = c(1.16, 1.01, 1.28, 0.79, 1.42, 1.15
                                                                                                                                                                                                                              ), HuefteL = c(1.16, 0.84, 1.46, 0.79, 0.99, 1.15), Balancerechts = c(90.58,
                                                                                                                                                                                                                                                                                                    86.27, 74, 104.65, 91.12, 124.21), Balancelinks = c(87.45,
                                                                                                                                                                                                                                                                                                                                                        91.5, 78.87, 102.71, 87.87, 111.8), Beschwerden = structure(c(3L,
                                                                                                                                                                                                                                                                                                                                                                                                                      3L, 3L, 2L, 1L, 2L), .Label = c("links", "No", "rechts"), class = "factor"),
                     Alter = c(60L, 58L, 48L, 27L, 47L, 37L), BMI = c(18.78, 21.8,
                                                                      21.15, 20.57, 19.14, 22.09), Geschlecht = structure(c(1L,
                                                                                                                            1L, 2L, 2L, 1L, 1L), .Label = c("M", "W"), class = "factor"),
                     X = c(NA, NA, NA, NA, NA, NA), Leistungsniveau = c(3L, 6L,
                                                                        5L, 9L, 7L, 2L), Trainingsumfang = c(12, 18, 18, 10.05, 14.5,
                                                                                                             19)), row.names = c(NA, 6L), class = "data.frame")
library (ggplot2)
scatter<-ggplot(runners, aes(ventraleK,Fragebogen))
scatter+geom_point()+ labs(x= "ventraleK", y= "Fragebogen")

Created on 2020-01-23 by the reprex package (v0.3.0)

Is it the last graph that you are having issues with?

Like @aosmith mentioned earlier, in the aes() the variable names don't need quotation marks.

scatter1<- ggplot(runners, aes(ventraleK, Fragebogen, color = Beschwerden)) +
  geom_point()+
  facet_wrap(~Beschwerden)

thanks a lot. I don't understand. There are my cods. What i have to do now?

runners <- read.table("runners.txt",sep = "\t",header = TRUE)
str(runners)
cor(runners)
pairs(~ventraleK+dorsaleK+lat.Krechts+lat.Klinks+Fragebogen+Frage1+Frage2+Frage3+Frage4+HuefteR+HuefteL+Balancerechts+Balancelinks+Beschwerden+Alter+BMI+Geschlecht+Leistungsniveau+Trainingsumfang, data=runners,main="Basic Scatter Plot Matrix")
library (corrgram)
corrgram(runners,order=TRUE, upper.panel=panel.ellipse,lower.panel=panel.conf,text.panel=panel.txt, main="Correlation Matrix runner")
library (ggplot2)
scatter<-ggplot(runners, aes("ventraleK","Fragebogen"))
scatter+geom_point()+ labs(x= "ventraleK", y= "Fragebogen")
scatter+geom_point()+ geom_smooth(method = "lm", colour= "Red", alpha =0.1, fill= "Blue")+
labs(x= "ventraleK", y= "Fragebogen")
#evtl. für Beschwerde-seite als Faktor

scatter+geom_point()+ geom_smooth(method = "lm",aes(fill= Beschwerden), colour= "Red", alpha =0.1, fill= "Blue")+
labs(x= "ventraleK", y= "Fragebogen", colour= "Beschwerden")#DK ist numerisch, Gender wäre eine Möglichkeit.

scatter1<- ggplot(runners, aes("ventraleK", "Fragebogen", color = Beschwerden)) +
geom_point()+
facet_wrap(~Beschwerden)
scatter1

it looks still like this

You have to change this part of your code

scatter<-ggplot(runners, aes("ventraleK","Fragebogen"))

to be

scatter<-ggplot(runners, aes(ventraleK,Fragebogen))

The difference is that there are no quotation marks around ventraleK and Fragebogen

There is the same problem in this line

scatter1<- ggplot(runners, aes("ventraleK", "Fragebogen", color = Beschwerden)) +

which needs to be

scatter1<- ggplot(runners, aes(ventraleK, Fragebogen, color = Beschwerden)) +

Also, in any place where you write the name of a color, such as

colour = "Red"

the color should be written in lower case

colour = "red"

thanks for you help. I did it. Then it can not find the object.

scatter+geom_point()+ labs(x= ventraleK, y= Fragebogen)
Fehler in list2(..., title = title, subtitle = subtitle, caption = caption, :
Objekt 'ventraleK' nicht gefunden

This is because for the labs ( = The axis labels) you need to put it in quotation marks, because here it es text then that you want to add.

perfect. it works. Thanks a lot