在R中重新缩放y轴

时间:2018-12-13 14:46:34

标签: r ggplot2

我正在编写一个R脚本,该脚本从表中读取列并使用ggplot2对其进行绘制。这样做很好,但是情节看起来像这样

dFig

如您所见,y轴不清晰,尽管之前已经提过这个问题,但似乎没有其他建议在这里起作用。我的代码包括

scaledfig <- function(x) sprintf("%.25f", x)
as.numeric(motionTable$abs_disp)
as.numeric(motionTable$rel_disp)

dFig <- ggplot(motionTable, aes(x = volNum, y = Displacement (mm), color = Displacement))
dFig <- dFig + geom_line(aes(y = motionTable$abs_disp, col = "Absolute", group = "Absolute"))
dFig <- dFig + geom_line (aes(y = motionTable$rel_disp, col = "Relative", group = "Relative"))
dFig <- dFig + geom_point(aes(y = motionTable$abs_disp, col = "Absolute"))
dFig <- dFig + geom_point (aes(y = motionTable$rel_disp, col = "Relative"))
dFig <- dFig + labs (x = "Volume Number", y = "Displacement (mm)", title = "Absolute and Relative Displacements")
dFig <- dFig + labs(title = paste("Subject", i))
dFig + scale_y_continuous(labels = scaledFig)
#dFig + scale_y_continuous(name = "Displacement (mm)", breaks = seq(0.0,2.0,0.25))
#dFig + scale_y_continuous(breaks = pretty_breaks(n=10)

dput(head(motionTable, 10))输出

structure(list(abs_disp = c("0", "0.3598496043", "0.3367404595", 
"0.5612950955", "0.5926686078", "0.6773828289", "0.7191384228", 
"1.060469172", "0.6591592446", "0.6038018978"), rel_disp = c("0", 
"0.3598496043", "0.2923699689", "0.4280773273", "0.1091926443", 
"0.1313908402", "0.1313493555", "1.560717967", "0.484082429", 
"0.1986202777"), tranX = c("0", "-0.0785146579", "-0.07608680893", 
"-0.07561987897", "-0.04065532835", "-0.06546745333", "-0.07439172898", 
"-0.2786683609", "-0.1795976768", "-0.18284101"), tranY = c("0", 
"0.1227999718", "-0.1630289336", "0.1584651318", "0.08877167101", 
"0.1767835047", "0.1202046746", "-0.1370894171", "-0.01578245448", 
"-0.1090108712"), tranZ = c("0", "-0.2684659095", "-0.2694665248", 
"-0.5203157126", "-0.5747761354", "-0.6256571446", "-0.6953128941", 
"0.7029104699", "0.2864873026", "0.1099864166"), rotX = c("0", 
"-0.003156857798", "-0.000892180542", "0.0004263653827", "0.001874236856", 
"0.00283550215", "0.003425042611", "0.01218409184", "0.009841443971", 
"0.01025226619"), rotY = c("-0", "0.000321621832", "-2.743286495e-05", 
"0.001403134549", "0.00132931408", "0.002377087483", "0.0002640777093", 
"0.002981501399", "0.00105366786", "0.001413969789"), rotZ = c("0", 
"0.0002346710389", "0.0001198071914", "0.001037030946", "0.001400115783", 
"0.001185192959", "0.001652514678", "5.723586582e-05", "0.001358391484", 
"0.001774424105"), fill = c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE)), class = c("data.table", "data.frame"
), row.names = c(NA, -10L), .internal.selfref = <pointer: 0x00000000026a1ef0>)

我已经尝试了以上所有方法,但仍然是一个奇怪的y轴。我想念什么?

0 个答案:

没有答案