I have a dataset of 2 variables and over 30k observations. one variable is country and the other is price. I want to plot the countries on the x axis but I only want to include certain rows(countries) such as "UK" & "USA" and not all the 20 countries listed in the column.
I am using ggplot but I am not sure how I would subset the dataset to include only those countries and their prices.
one_plot <- subset(origin_price$product_origin == c["USA", "UK", "Australia", "China"])
I tried to subset using the above code which is wrong, but Im struggling to find any solutions online to this particular problem.
y = sample(1:1000,1000) #price
x = sample(letters, 1000, replace = T) #country names
library(ggplot2)
d = data.frame(x,y)
d = subset(d, x == "a"| x == "b")
Use subset
to subset dataframe and |
to separate the countries you want to plot.
u = ggplot(d, aes(x = x, y = y))
u + geom_point() # that is it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.