使用R ggplot中特定列的几个值进行绘图



我有一个名为city的列,它有10多个不同的城市,这些值分散在10000行中。现在我想在10个城市中,根据具体的城市进行一些探索性的分析。我目前写的-

ggplot(irdata,aes(x=City))+geom_histogram(binwidth=5)
ggplot(irdata, aes(x = City,y=50, fill = Section)) +geom_bar(stat = "identity", position = "dodge") + coord_flip()

在这两个情节中,我都使用了我不想要的所有城市。如何使用等特定城市进行绘图

ggplot(irdata,aes(x=City=='Dublin'))+geom_histogram(binwidth=5)

但上面的代码无论如何都不会起作用,因为它会带来逻辑输出/的结果。

尝试:

ggplot(irdata[irdata$City=='Dublin',],aes(x=City))+geom_histogram(binwidth=5)

只对数据进行子集处理怎么样?

ggplot(subset(irdata, City == "Dublin"),aes(x=City))+geom_histogram(binwidth=5)

这应该是一个注释,因为它与其他答案基本相同(除了"City%in%.."),但我不允许删除它:-(

ggplot(subset(irdata, City %in% c("Dublin","Cork","London")), aes(x=City)) + 
geom_histogram(binwidth=5)

最新更新