dotPlot无法正确显示点颜色

时间:2015-09-02 22:13:55

标签: r

我有一个点图,我想为点着色,所以我有一个d$color向量,对应于特定点的颜色。

问题1: 当您运行下面的代码时,您可以看到点没有正确着色?你知道如何正确着色吗?代码需要动态处理颜色变化的情况。例如,在这种情况下,“红色”是第一种颜色,但情况并非总是如此。

问题2:您是否也知道如何填充点而不是透明?

library(mosaic)
binwidth <- 1
dat <- c(1, 1, 1, 2, 3, 3, 4, 4, 5, 5)
d <- data.frame(x=dat, color=c("red", "green", "blue", "blue", "purple", "red",
                               "red", "blue", "green", "green"))
dotPlot(~x, data=d, groups=color, 
        breaks=seq(min(d$x) - binwidth, max(d$x) + binwidth, binwidth), 
        cex=1, col=as.factor(d$color))

问题3:你能运行这段代码吗?解决方案似乎不适用于此:

n=50
r =rnorm(n)
dat = sample(r ,n= 1,size = n, replace = TRUE)
d = data.frame( x = dat, color = c(rep("red",n/2), rep("green",n/2)))
dotPlot(d$x,  breaks = seq(min(d$x)-.1,max(d$x)+.1,.1)) # this works
dotPlot(d$x,  breaks = seq(min(d$x)-.1,max(d$x)+.1,.1), groups = color,col = levels(d$color) ) # this does not work

2 个答案:

答案 0 :(得分:1)

关于Q2,只需使用参数“pch”默认更改“点”的类型。

"\n"

答案 1 :(得分:1)

要根据需要为点着色,请传递与您想要的颜色对应的颜色矢量(所以这里是4种颜色的矢量,而不是10种颜色的矢量)。

@Override
public Page<T> findAll(Predicate predicate, Pageable pageable) {

    JPQLQuery countQuery = createQuery(predicate);
    JPQLQuery query = querydsl.applyPagination(pageable, createQuery(predicate));
....
}

protected JPQLQuery createQuery(Predicate... predicate) {

    JPAQuery query = querydsl.createQuery(path).where(predicate);
    CrudMethodMetadata metadata = getRepositoryMethodMetadata();

    if (metadata == null) {
        return query;
    }

    LockModeType type = metadata.getLockModeType();
    query = type == null ? query : query.setLockMode(type);

    for (Entry<String, Object> hint : getQueryHints().entrySet()) {
        query.setHint(hint.getKey(), hint.getValue());
    }

    return query;
}

enter image description here

要更改符号,请使用public interface SomeRepository extends JpaRepository<SomeEntity, Long>, QueryDslPredicateExecutor<SomeEntity>, SomeRepositoryCustom { } public interface SomeRepositoryCustom { Page<SomeEntity> findAll(Predicate predicate, Pageable pageable); } public class SomeRepositoryImpl extends SimpleJpaRepository<SomeEntity, Long> implements SomeEntityRepositoryCustom { private final EntityManager entityManager; private final EntityPath<SomeEntity> path; private final PathBuilder<SomeEntity> builder; private final Querydsl querydsl; @Autowired public SomeRepositoryImpl(EntityManager entityManager) { super(SomeEntity.class, entityManager); CrudMethodMetadata metadata = getRepositoryMethodMetadata(); this.entityManager = entityManager; this.path = SimpleEntityPathResolver.INSTANCE.createPath(SomeEntity.class); this.builder = new PathBuilder<>(path.getType(), path.getMetadata()); this.querydsl = new Querydsl(entityManager, builder); } @Override public Page<SomeEntity> findAll(Predicate predicate, Pageable pageable) { JPAQuery countQuery = createQuery(predicate); JPAQuery query = (JPAQuery) querydsl.applyPagination(pageable, createQuery(predicate)); query.setHint(EntityGraph.EntityGraphType.LOAD.getKey(), entityManager.getEntityGraph("YOUR GRAPH KEY")); Long total = countQuery.count(); List<SomeEntity> content = total > pageable.getOffset() ? query.list(path) : Collections.<SomeEntity> emptyList(); return new PageImpl<>(content, pageable, total); } private JPAQuery createQuery(Predicate predicate) { return querydsl.createQuery(path).where(predicate); } } (有关内置绘图字符的列表,请参阅function tada() { $(".arrow").addClass("tada"); setTimeout(function () { $(".arrow").removeClass("tada"); }, 1000); } var j = 0; function thumb() { if(j < 18) { setInterval(function () { $('.equip-thumb').eq(j).css('opacity', '1'); j++; }, 100); } } $(document).ready(function(){ for (var i = 0; i < 18; i++) { var color = "#1b1f25"; if ((i%3) === 0) { color = "#1b222c"; } if ((i%3) === 1) { color = "#171c23"; } if ((i%3) === 2) { color = "#2a313b"; } $('.equip-thumb').eq(i).css("background-color", color); } }); var fired = 0; $(window).scroll(function(){ var wScroll = $(this).scrollTop(); var wHeight = $(this).height(); $(".arrow").css({ 'opacity' : 1-wScroll/wHeight/0.5 }); $("#splash").css({ 'transform' : 'translate(-'+ wScroll /10 +'% , 0px)', 'opacity' : 1-wScroll/wHeight/0.5 }); if(wScroll > ($('.section-equipment').offset().top - 0.6*wHeight)) { if (fired === 0) { fired = 1; thumb(); } } }); $(function() { setInterval(function () { tada(); }, 4000); $('.equip-thumb').on({ mouseover: function(){ $(this).children().css('transform', 'translate(0px, 0px)'); }, mouseleave: function() { $(this).children().css('transform', 'translate(0px, 100%)'); }, click: function(){ $(this).siblings().children().css('transform', 'translate(0px, 100%)'); $(this).children().css('transform', 'translate(0px, 0px)'); } }); $('#portfolio-a').click(function (){ $('html, body').animate({ scrollTop: $('.section-portfolio').offset().top - 65 }, 1000); }); $('#equipment-a').click(function (){ $('html, body').animate({ scrollTop: $('.section-equipment').offset().top - 65 }, 1000); }); $('#contact-a').click(function (){ $('html, body').animate({ scrollTop: $('.section-contact').offset().top - 65 }, 1000); }); }); )。

dotPlot(~x, data=d, groups=color, col=levels(d$color),
        breaks=seq(min(d$x) - binwidth, max(d$x) + binwidth, binwidth))

enter image description here