如何用ggplot生成非标准图型? [英] How to produce non-standard plot type with ggplot?
问题描述
我想用ggplot做一个看起来非常接近的情节(在这里找到):
然而,我想绘制条件的范围,而不是频率。这里是我想用5个条件制作的情节草图:
我的数据被安排为范围的开始和结束坐标。例如,对于条件5,范围的开始为30,范围的结束为40(为了清楚起见,我已将其标记为图形)。我的数据来自以下格式的文件:
id start end
1 20 35
2 60 75
3 10 30
4 80 90
5 30 40
我有大约100个开始和结束值,我想用这种方式在一张图上绘制。最后的情节应该只有两种颜色。
更新:
类似这样的内容:
library ggplot2)
library(reshape)
dat < - data.frame(lets = letters [1:5],low = 1:5,mid = 3:7,high = 10:14)
dat.melt< - melt(dat,id.vars ='let')
ggplot(dat.melt,aes(x = lets,y = value,fill =变量))+
geom_bar(stat ='identity')+
scale_fill_manual(breaks = c('low','mid','high'),values = c('blue','红色','蓝色'))+
coord_flip()
数据...
I would like to make a plot with ggplot that looks very close to this (found here):
However, instead of frequency I would like to plot ranges for conditions. Here is a sketch of the plot I want to produce with 5 conditions:
My data is arranged as a start and end coordinate for the range. For example, for condition 5 the start of the range is 30 and the end of the range is 40 (I've labeled this about the graph for clarity). My data is from a file in the form:
id start end
1 20 35
2 60 75
3 10 30
4 80 90
5 30 40
I have about 100 start and end values that I would like to plot in this manner on one graph. The final plot should be only two colors.
UPDATE:
For future reference, Justin's solution produces this:
Something like this:
library(ggplot2)
library(reshape)
dat <- data.frame(lets=letters[1:5], low=1:5, mid=3:7, high=10:14)
dat.melt <- melt(dat, id.vars='lets')
ggplot(dat.melt, aes(x=lets, y=value, fill=variable)) +
geom_bar(stat='identity') +
scale_fill_manual(breaks=c('low','mid','high'), values=c('blue','red','blue')) +
coord_flip()
But fairly dependent on your data...
这篇关于如何用ggplot生成非标准图型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!