ggplot2-如何在离散刻度轴值中绘制连续值?
ggplot2- How to plot continues values in a discrete scale axis values?
我有连续值(请参阅下面数据中的 cols log
),我想用 ggplot2 绘制成一个 char 线。我的代码实际上完成了这项工作但我的问题是 y 轴的值。事实上,这些值分布不均,因此该图造成了比例尺的错误视觉感知(例如,参见下图第三图中绿线和蓝线之间的 space)
我该如何解决这个问题?有没有办法强制 y 轴围绕离散值(如 (0,1,2,3,4,5,6,7))组织数据中的计数值?
这是我的数据
motor;trace;rules;time;log
monetDBIE;1m;R2;1556;3,1
monetDBIE;1m;R1;1590;3,2
monetDBIE;1m;RDFS;15999;4,2
monetDBIE;2m;R2;3319;3,5
monetDBIE;2m;R1;3645;3,5
monetDBIE;2m;RDFS;31239;4,4
monetDBIE;5m;R2;9283;3,9
monetDBIE;5m;R1;10398;4
monetDBIE;5m;RDFS;85806;4,9
Jena;1m;R1;227;2,3
Jena;1m;R2;1203228;6
Jena;1m;RDFS;21;1,3
Jena;2m;R1;321;2,5
Jena;2m;R2;5099199;6,7
Jena;2m;RDFS;21;1,3
Jena;5m;R1;629;2,7
PGSQLIE;1m;R1;8149;3,9
PGSQLIE;1m;R2;6548;3,8
PGSQLIE;1m;RDFS;66116;4,8
PGSQLIE;2m;R1;17029;4,2
PGSQLIE;2m;R2;22523;4,3
PGSQLIE;2m;RDFS;81155;4,9
PGSQLIE;5m;R1;33483;4,5
PGSQLIE;5m;R2;1504944;6,1
PGSQLIE;5m;RDFS;891532;5,9
这是我的 ggplot2 代码
require("ggplot2")
w <- read.csv(file="saturation/saturation.csv", head=TRUE, sep=";")
p <- ggplot(data=w, aes(x=trace, y=log, colour=motor, shape=motor))
p <- p + geom_point(size=4)
p <- p + geom_line(size=1,aes(group=motor))
p <- p + geom_text(aes(label=time), hjust=-0.2, vjust=1)
p <- p + ggtitle("Insertion des triplets (R1, R2) et saturation RDFS dans triplestores")
p <- p + scale_fill_continuous(guide = guide_legend(title = NULL))
p <- p + facet_grid(rules~.)
p <- p + theme_bw()
postscript(file = 'saturation.vs.eps')
print (p)
在这种情况下,您真的想要一个离散的 y 尺度吗?如果将 w$log
更改为数字,则图表的格式将是 "correctly":
# Convert log variable to numeric and substitute commas with decimals
w$log <- as.numeric(sub(",", ".", w$log, fixed=TRUE))
ggplot(data=w, aes(x=trace, y=log, colour=motor, shape=motor)) +
geom_point(size=4) +
geom_line(size=1,aes(group=motor)) +
geom_text(aes(label=time), hjust=-0.2, vjust=1) +
ggtitle("Insertion des triplets (R1, R2) et saturation RDFS dans triplestores") +
scale_fill_continuous(guide = guide_legend(title = NULL)) +
facet_grid(rules~.) +
theme_bw()
如果您坚持使用离散的 y 尺度,则可以使用 scale_y_discrete(breaks=0:7, labels=0:7)
。
仅供参考 - 您可能想在 geom_text
中添加 show_guide = FALSE
以从图例中删除 a
...即 geom_text(aes(label = time), hjust=-0.2, vjust=1, show_guide=FALSE)
我有连续值(请参阅下面数据中的 cols log
),我想用 ggplot2 绘制成一个 char 线。我的代码实际上完成了这项工作但我的问题是 y 轴的值。事实上,这些值分布不均,因此该图造成了比例尺的错误视觉感知(例如,参见下图第三图中绿线和蓝线之间的 space)
我该如何解决这个问题?有没有办法强制 y 轴围绕离散值(如 (0,1,2,3,4,5,6,7))组织数据中的计数值?
这是我的数据
motor;trace;rules;time;log
monetDBIE;1m;R2;1556;3,1
monetDBIE;1m;R1;1590;3,2
monetDBIE;1m;RDFS;15999;4,2
monetDBIE;2m;R2;3319;3,5
monetDBIE;2m;R1;3645;3,5
monetDBIE;2m;RDFS;31239;4,4
monetDBIE;5m;R2;9283;3,9
monetDBIE;5m;R1;10398;4
monetDBIE;5m;RDFS;85806;4,9
Jena;1m;R1;227;2,3
Jena;1m;R2;1203228;6
Jena;1m;RDFS;21;1,3
Jena;2m;R1;321;2,5
Jena;2m;R2;5099199;6,7
Jena;2m;RDFS;21;1,3
Jena;5m;R1;629;2,7
PGSQLIE;1m;R1;8149;3,9
PGSQLIE;1m;R2;6548;3,8
PGSQLIE;1m;RDFS;66116;4,8
PGSQLIE;2m;R1;17029;4,2
PGSQLIE;2m;R2;22523;4,3
PGSQLIE;2m;RDFS;81155;4,9
PGSQLIE;5m;R1;33483;4,5
PGSQLIE;5m;R2;1504944;6,1
PGSQLIE;5m;RDFS;891532;5,9
这是我的 ggplot2 代码
require("ggplot2")
w <- read.csv(file="saturation/saturation.csv", head=TRUE, sep=";")
p <- ggplot(data=w, aes(x=trace, y=log, colour=motor, shape=motor))
p <- p + geom_point(size=4)
p <- p + geom_line(size=1,aes(group=motor))
p <- p + geom_text(aes(label=time), hjust=-0.2, vjust=1)
p <- p + ggtitle("Insertion des triplets (R1, R2) et saturation RDFS dans triplestores")
p <- p + scale_fill_continuous(guide = guide_legend(title = NULL))
p <- p + facet_grid(rules~.)
p <- p + theme_bw()
postscript(file = 'saturation.vs.eps')
print (p)
在这种情况下,您真的想要一个离散的 y 尺度吗?如果将 w$log
更改为数字,则图表的格式将是 "correctly":
# Convert log variable to numeric and substitute commas with decimals
w$log <- as.numeric(sub(",", ".", w$log, fixed=TRUE))
ggplot(data=w, aes(x=trace, y=log, colour=motor, shape=motor)) +
geom_point(size=4) +
geom_line(size=1,aes(group=motor)) +
geom_text(aes(label=time), hjust=-0.2, vjust=1) +
ggtitle("Insertion des triplets (R1, R2) et saturation RDFS dans triplestores") +
scale_fill_continuous(guide = guide_legend(title = NULL)) +
facet_grid(rules~.) +
theme_bw()
如果您坚持使用离散的 y 尺度,则可以使用 scale_y_discrete(breaks=0:7, labels=0:7)
。
仅供参考 - 您可能想在 geom_text
中添加 show_guide = FALSE
以从图例中删除 a
...即 geom_text(aes(label = time), hjust=-0.2, vjust=1, show_guide=FALSE)