有谁知道如何控制ggplot2中的图例排序?
从我可以看到,订单显示与实际比例标签相关,而不是比例声明顺序.更改比例标题会改变顺序.我用钻石数据集做了一个小例子来强调这一点.我正在尝试将ggplot2用于一系列图表,我想让一个变量出现在右边的所有图表中.目前虽然这只发生在其中一些,但我在如何强制执行我想要的订购同时保留适当的比例标签时不知所措.
library(ggplot2)
diamond.data <- diamonds[sample(nrow(diamonds), 1000), ]
plot <- ggplot(diamond.data, aes(carat, price, colour = clarity, shape = cut)) +
geom_point() + opts(legend.position = "top", legend.box = "horizontal")
plot # the legend will appear shape then colour
plot + labs(colour = "A", shape = "B") # legend will be colour then shape
plot + labs(colour = "Clarity", shape = "Cut") # legend will be shape then colour
Run Code Online (Sandbox Code Playgroud) 最近我一直在查看Steven Skiena的"算法设计手册"的在线资源中的一些C示例代码,并且对他的一些函数调用的语法感到困惑.不可否认,自从C在uni工作已经有一段时间了,但我从来没有遇到像这样的无类型函数参数:
find_path(start,end,parents)
int start;
int end;
int parents[];
{
if ((start == end) || (end == -1))
printf("\n%d",start);
else {
find_path(starts,parents[end],parents);
printf(" %d",end);
}
}
Run Code Online (Sandbox Code Playgroud)
这是有效的语法吗?这种功能声明是否有任何好处?它似乎比传统的内联类型参数更冗长.
我一直在编写一个Makefile来执行一些依赖项生成,我发现自己不得不重复规则,因为(遗留)代码库包含.cpp
和.cc
文件的混合.看起来有点不雅观.无论如何要指定目标的先决条件可以是文件.cpp
还是.cc
文件?
所以,而不是:
%.d : %.cpp
$(CPP) -MM $(CPPFLAGS) $<
%.d : %.cc
$(CPP) -MM $(CPPFLAGS) $<
Run Code Online (Sandbox Code Playgroud)
创建没有重复的东西,如:
%.d : %.(cpp | cc)
$(CPP) -MM $(CPPFLAGS) $<
Run Code Online (Sandbox Code Playgroud)
或者这种强制冗余只是GNU Make设计的一个不幸因素?
我试图阻止Scala的一个属性case class
被序列化.我已经尝试用通常的方式注释有问题的财产@JsonIgnore
,我也尝试将其附加@JsonIgnoreProperties(Array("property_name"))
到case class
.这两者似乎都达不到我想要的.
这是一个小例子:
import org.json4s._
import org.json4s.jackson._
import org.json4s.jackson.Serialization
import org.json4s.jackson.Serialization.{read, write}
import com.fasterxml.jackson.annotation._
object Example extends App {
@JsonIgnoreProperties(Array("b"))
case class Message(a: String, @JsonIgnore b: String)
implicit val formats = Serialization.formats(NoTypeHints)
val jsonInput = """{ "a": "Hello", "b":"World!" }"""
val message = read[Message](jsonInput)
println("Read " + message) // "Read Message(Hello,World!)
val output = write(message)
println("Wrote " + output) // "Wrote {"a":"Hello","b":"World!"}"
}
Run Code Online (Sandbox Code Playgroud) 我写了一个相当简单的测试Makefile
,我定义了两个目标,all&clean.我有两个不同的条件语句.一个检查是否存在$(MAKECMDGOALS)
特殊变量,另一个检测命令行目标是否与变量(NODEPS
)中列出的目标匹配.我遇到的问题是我的条件中没有任何分支被执行.最终,我想使用条件来决定我提供的目标是否应该包含一些自动生成的依赖文件,但目前我正努力让任何一个表达式进行评估.我正在运行GNU make 3.81版,我在Ubuntu和Mac OS X下试过它无济于事.
NODEPS := clean
INCLUDE = $(filter $(NODEPS),$(MAKECMDGOALS))
.PHONY : all clean
ifndef $(MAKECMDGOALS)
@echo "$$(MAKECMDGOALS) is not defined"
else
@echo "$(MAKECMDGOALS) is defined"
endif
ifneq (0, $(words $(INCLUDE)))
@echo "INCLUDE = $(INCLUDE) != 0"
else
@echo "INCLUDE = $(INCLUDE) == 0"
endif
all :
@echo "all : $(MAKECMDGOALS)"
clean :
@echo "clean : $(MAKECMDGOALS)"
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用网格库的densityplot
功能来显示一些数据.我的数据集非常杂乱,所以我想减少底部绘制的符号的alpha值(这样可以在过度绘图的情况下获得更清晰的视图).但是,我似乎无法改变那些符号的alpha值而不会使实际密度曲线同样不透明.我使用的是图形的par.settings
选择和设定不同的值superpose.line
和superpose.symbol
(和工程变更线的种类及符号,但由于某种原因未阿尔法值).我用虹膜数据集做了一个小例子来说明我的问题/当前的方法.如果有人有任何建议我会非常感激.
library(lattice)
data(iris)
graph.settings <- list(superpose.line = list(lty = 1:3, lwd = 2, alpha = 1),
superpose.symbol = list(pch = 1:3, alpha = 0.3))
densityplot( ~ Sepal.Length, data = iris, groups = Species,
auto.key = list(columns = 3), aspect = 1,
main = "Density Plot of Sepal Lengths", xlab = "Length (mm)",
par.settings = graph.settings)
Run Code Online (Sandbox Code Playgroud) 我有一个包含一些初始值的现有data.frame.我想要做的是创建另一个data.frame,其中第一个data.frame中的每一行都有10个随机采样的行.我也试图以R方式做这个,所以我想避免迭代.
到目前为止,我已经设法将一个函数应用于表中生成一个值的每一行,但是我不知道如何将其扩展为每个应用程序生成10行,然后将结果重新绑定.
到目前为止,这是我的进展:
样本数据:
starts <- structure(list(instance = structure(21:26, .Label = c("big_1",
"big_10", "big_11", "big_12", "big_13", "big_14", "big_15", "big_16",
"big_17", "big_18", "big_19", "big_2", "big_20", "big_3", "big_4",
"big_5", "big_6", "big_7", "big_8", "big_9", "competition01",
"competition02", "competition03", "competition04", "competition05",
"competition06", "competition07", "competition08", "competition09",
"competition10", "competition11", "competition12", "competition13",
"competition14", "competition15", "competition16", "competition17",
"competition18", "competition19", "competition20", "med_1", "med_10",
"med_11", "med_12", "med_13", "med_14", "med_15", "med_16", "med_17",
"med_18", "med_19", "med_2", "med_20", "med_3", "med_4", "med_5",
"med_6", "med_7", "med_8", "med_9", "small_1", "small_10", "small_11",
"small_12", "small_13", "small_14", "small_15", "small_16", "small_17", …
Run Code Online (Sandbox Code Playgroud)