0
votes

Dataframe wanting to plot

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
List of AvgPwill

#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

1
Maybe try plot(Pwill1)Duck
Try Pwill1 <- ggplot(AvgPWill, aes(Values))+geom_histogram()Duck
Still a list using Pwill1 <- ggplot(AvgPWill, aes(Values))+geom_histogram()jeffbeckinc
qplot(AvgPWill$Segment, AvgPWill$Values) creates a plot but I cannot seem to get beyond doing this scatterplotjeffbeckinc
That worked @Dave2e. I would like to mark that as the answer. Thank you for your help with that answer and editing. I'm still relatively new to Stack Overflowjeffbeckinc

1 Answers

3
votes

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()