我正在尝试根据Google Earth引擎中的属性从要素集合创建直方图,以便我可以提供标题和轴标题。 ui.Chart.feature.histogram
似乎不允许这样做。但是,它确实为图表提供了正确的数据。
我也尝试过使用aggregeate_histogram(property)
方法,将其转换为字典,并从字典中访问.values()
和.keys()
并对它们进行排序。但是,这会将数据按顺序排列,但逻辑上却不合理,例如3出现在29之后,而不是4之前。
与ui.Chart.array.values()
和ui.Chart.feature.histogram
相比,我使用的是 initialmth <- structure(list(
A = c( 10, 4),
B = c(28, 18),
C = c(9, 1),
D = c(39, 33),
E = c(13, 8),
F = c(37, 27),
G = c(30, 51),
H = c(31, 41)),
.Names = c("Math has been my worst subject ",
"I would consider a career that uses math ",
"Math is hard for me",
"I am the type of student to do well in math",
"I cannot do a good job with math",
"I could do advanced work in math",
"I can get good grades in math",
"I am good at math"
),
class = "data.frame",
row.names = c(NA, -2L)) #4L=number of numbers in each letter vector#
attach(initialmth)
print(initialmth)
initialmth <- initialmth[, order(colSums(initialmth))]
xFun <- function(x) x/2 + c(0, cumsum(x)[-length(x)])
par(mar=c(2, 17, 1, 2))
colors <- c("slategray3", "dodgerblue4")
byc <- barplot(as.matrix(initialmth),
beside = F, ylim = range(0, 15), xlim = range(0, 100),
horiz = T, col=colors, main="N=96", border=F, las=1, width
= 1.45, axes = 'n')
#adds % to scale
scale <- seq(0, 100, by = 20)
axis(side = 1, at = scale, labels = paste0(scale, "%"), cex.axis = 1)
#this adds gridlines
grid(nx = NULL, ny = nx, col = "lightgray", lty = "dotted",
lwd = par("lwd"), equilogs = TRUE)
# labels
labs <- data.frame(x=as.vector(sapply(initialmth, xFun)), # apply `xFun`
here
y=rep(byc, each=nrow(initialmth)), # use `byc` here
labels=as.vector(apply(initialmth, 1:2, paste0, "%")),
stringsAsFactors=FALSE)
labs$labels[labs$labels %in% paste0(0:(8*100)/100, "%")] <- "" #masks
labels <8
invisible(sapply(seq(nrow(labs)), function(x) # `invisible` prevents
unneeded console output
text(x=labs[x, 1:2], labels=labs[x, 3], cex=.9, font=2, col=0)))
和字典值和键:
result of ui.Chart.array.values()
vs。
答案 0 :(得分:0)
我没有意识到.setOptions()
上也可以使用ui.Chart.feature.histogram
方法!这样我就可以提供标题。