简体   繁体   English

仅使用x轴上的列和y轴上的整列中的某些行值来创建图

[英]Create a plot using only certain row values from a column in the x axis and the full column on the y axis

I have a dataset of 2 variables and over 30k observations. 我有2个变量和超过30k观测值的数据集。 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. 我想在x轴上绘制国家/地区,但我只想包括某些行(国家/地区),例如“英国”和“美国”,而不是列中列出的所有20个国家/地区。

I am using ggplot but I am not sure how I would subset the dataset to include only those countries and their prices. 我正在使用ggplot,但是我不确定如何将数据集子集化为仅包括那些国家及其价格。

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 | 使用subset对数据框进行子集化| to separate the countries you want to plot. 分隔要绘制的国家。

u = ggplot(d, aes(x = x, y = y))
u + geom_point()  # that is it. 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM