Reputation: 13
The image is 5 rows and two variables I am wanting to plot and below is my code I am using.
The second image shows the results
#histogram plot
Pwill1 <- ggplot(AvgPWill, aes(Segment))+geom_histogram()
#Structure of AvgPWill
str(AvgPWill)
'data.frame': 5 obs. of 2 variables:
$ Segment: chr "Costcutter" "Innovator" "Mercedes" "Workhorse" ...
$ Values : num 2084 3595 4695 2994 3422
I am not familiar with the plot function but I tried this and received this error:
plot(AvgPWill$Segment, AvgPWill$Values)
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf
Upvotes: 1
Views: 2478
Reputation: 24139
Yes, the output from the ggplot function is a list containing the structure of the plot. To display the plot use: print(Pwill1)
.
Also since you have only 5 rows of data, I believe you want to use geom_col()
instead of geom_histogram()
.
Values= runif(5, 2000, 3000)
AvgPWill = data.frame(Segment=LETTERS[1:5], Values)
library(ggplot2)
Pwill1 <- ggplot(AvgPWill, aes(x=Segment, y=Values))+geom_col()
print(Pwill1)
If you want to use the base graphics then try barplot()
Upvotes: 5